使包装的属性可绑定
我有 Class1
和一个名为 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"));
}
}
我还有 Class2
,其中包含 Class1
的私有实例代码>.我想让属性 age
从 Class1
可用并且仍然可绑定。
public class Class2 {
private var c1:Class1 = new Class1();
[Bindable????]
public function get age():int {
}
}
当然,那里的 [Bindable]
标记没有意义。但怎样才能达到同样的效果呢?
我相信我可以从 Class2
到 Class1
调度某种 ageChanged
事件,然后在 Class1
中有一个事件处理程序> 调度另一个本地 ageChanged
事件,我将 Class2 的 age
属性绑定到该事件。
但这听起来不必要地复杂。难道就没有更简单的方法吗? :)
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用类似的东西:
Try to use something like:
就我个人而言,我只是将我的复合类设置为公共,并从视图中访问它(如果它是模型)(我认为是模型)。如果您不想这样做,可以随时使用 BindingUtils:
在类2构造函数中
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