I have Class1 with a read-only bindable property called age:
public class Class1 {
private var _age:int;
[Bindable(event="ageChanged"]
public function get age():int {
return this._age;
}
public function something():void {
_age++;
dispatchEvent(new Event("ageChanged"));
}
}
I also have Class2 which contains a private instance of Class1. And I want to make property age available from Class1 and still be bindable.
public class Class2 {
private var c1:Class1 = new Class1();
[Bindable????]
public function get age():int {
}
}
Of course the [Bindable] tag there doesn’t make sense. But how can I achieve the same effect?
I believe I can dispatch some sort of ageChanged event from Class2 up to Class1 and then have an event handler in Class1 dispatch another local ageChanged event to which I bind Class2‘s age property.
But this sounds unnecessarily complicated. Isn’t there a simpler way? 🙂
Thanks!
Personally, I’ve just put my composite class as public and access it from the view if it’s a model (which i think it is). If you don’t want to do that, you can always use BindingUtils:
In the class 2 constructor