Quick tip: invalidating properties on bindables changed

By default, flex bindable properties fires event PropertyChangeEvent.PROPERTY_CHANGE. Sure, those events can be listened thus you can play with them. This can be useful when you have a lot of bindable properties in your classes and you do not want to make getter and setter for each just to be able to catch the moment of update:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" 
    import mx.events.PropertyChangeEvent;
    [Bindable] private var bVar:uint = 0;
    [Bindable] private var btnLabel:String = "";
    private function creationCompleteHandler():void
        addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, propertyChangedHandler);
    private function propertyChangedHandler(event:PropertyChangeEvent):void
        if(event.property == "bVar")
    override protected function commitProperties():void
        btnLabel = bVar.toString();
<mx:Button click="bVar++" label="{btnLabel}"/>

Leave a comment

Please be polite and on topic. Your e-mail will never be published.