Can anyone please help me solve this mystery:
I’ve got a component called Box.as that has following two properties, and have their getters & setters defined:
private var _busy:Boolean;
private var _errorMessage:String;
In MXML that uses this component I define it like this:
<components:Box skinClass="skins.components.BoxSkin"
busy="{presenter.boxBusy}"
errorMessage="{presenter.boxErrorMessage}"/>
Where presenter variable is defined here in MXML and a Presenter class has boxBusy and boxErrorMessage variables defined as bindable property change events:
[Bindable(event="propertyChange")]
function get boxBusy():Boolean;
function set boxBusy(value:Boolean):void;
[Bindable(event="propertyChange")]
function get boxErrorMessage():String;
function set boxErrorMessage(value:String):void;
PROBLEM is that whenever I change boxErrorMessage for the presenter, I see the affect in MXML but nothing happens at all when I change boxBusy. Is there something extra I need to do with boolean variable?
Thanks a lot in advance.
You should omit the
(event="propertyChange")specification from your[Bindable]metadata tags on bothboxBusyandboxErrorMessage. Also, make sure your get/set methods are declared public.So, the property,
boxBusy, would look something like this:When you qualify
[Bindable]with(event="..."), you’re telling Flex, “I will dispatch the named event whenever the binding should be updated”.If you omit the event specification, then flex assumes that the event is named
propertyChange. But that’s not all it does. It also automatically “wraps” your setter with generated code that transparently dispatches a'propertyChange'event any time the setter is used to modify the value. This is described in more detail here, at adobe livedocs.So… by explicitly specifying
(event="propertyChange"), you disable flex’s default behavior. Even though you’re using the default event name, flex will not generate the wrapper code — instead, it will expect you to dispatch the event from your code, at the appropriate time.I imagine that your
boxErrorMessageproperty appears to be working, because some other[Bindable]property of your class is changing in the same pass — thus dispatchingpropertyChange, and causing yourboxErrorMessagebinding to update as a side-effect.