Lets say I have the following:
public class MyObject { [Bindable] public var foo:int = 3; } ... [Bindable] var _obj:MyObject = null;
What’s the best way to bind foo so that this binding is updated when _obj is set to a new instance?
I’ve tried:
<mx:Label text='{_obj&&_obj.foo}'/>
But it isn’t pretty. Can I express this somehow using
What do the SO::Flex community think?
Binding doesn’t depend on properties; you can get the benefits of binding with either fields or properties.
It looks like you might’ve left something out, maybe? The following MXML and AS, for example, work to bind on both a field and a property, once the class and its instance are marked Bindable:
Incidentally, the effect would be the same if you marked the field and the property Bindable separately, rather than marking the class, which is just shorthand for the same thing. Also note myFoo starts out null by default, as in your sample code (i.e., the ‘ = null’ assignment is redundant).
Does this example help? If not, leave a comment and I’ll check back. Hope it does!