views:

270

answers:

3

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 displays "initialized"

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

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.

Cory Petosky
A: 

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.

Edited my answer.
Cory Petosky
Ok thanks Cory, I'll try that out today and post back with my results.
A: 

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.

Cosma Colanicchia