开发者

Flex AS3 - Creating a dynamic property, and then binding a control to it

I am trying to: 1) create a dynamic property 2) bind that property to a label

This works great for "sealed properties", but for dynamic properties there doesn't appear to be any event triggered. Are dynamic properties implicityly not bindable?

var myObj:MyType = new MyType(); // MyType is dynamic
myObj["myDynamicPropertyName"] = "initialized";

BindingUtils.bindProperty(myLabel, "data", myObj, repeatedLabel.name); // myLabel now di开发者_如何学运维splays "initialized"

myObj["myDynamicPropertyName"] = "changed";  // myLabel still displays "initialized", it should say "changed" !!!


mwilson: No compiler warnings

Cory Petosky: I tried that earlier, the method is called first time I set the dynamic property, but not the second.


Try BindingUtils.bindProperty(myLabel, "data", myObj, { name: repeatedLabel.name, getter: function(host) { return host[repeatedLabel.name]; } });

Dynamic properties don't appear in describeType, so apparently the system can't bind to them.

If your type doesn't already extend something, you could extend Proxy and override the setProperty function to dispatch data change events. If it does already extend something... you'll have to figure out another workaround.


You could wrap your object into an mx.utils.ObjectProxy and then use this wrapper to place your listeners. However, you also should use this wrapper, instead of the original object, to update the values of those properties, in order for the correct binding events to be fired.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜