The problem: I’ve got a Flex class with all its properties well defined. It’s good for me, it has all the properties I need to represent correctly the model, but sometimes I wish I had a few more properties to use it in some contexts. These additional properties are not strictly related to the model I want to represent, so I don’t want to add them to the class, but I need them to easily integrate with Flex components functionalities for user interaction.
The solution: DynaObjectProxy!
Before looking through the source code of DynaObjectProxy, let’s talk briefly about what it does. Basically, it’s a sort of ObjectProxy, but it extends its functionalities.
With ObjectProxy you can wrap a class instance and access to its properties through the proxy
// MyClass contains the property "prop1" var myClassInstance: MyClass = new MyClass(); myClassInstance.prop1 = "The value"; var myProxy: ObjectProxy = new ObjectProxy(myClassInstance); trace(myProxy.prop1); // Outputs "The value"
but you cannot dynamically create new properties in the ObjectProxy instance
trace(myProxy.prop2); // ERROR! "prop2" doesn't exist in MyClass
Otherwise, you can create an ObjectProxy instance without wrapping a class instance and in this case you actually can create new properties in the ObjectProxy
var myProxy: ObjectProxy = new ObjectProxy(); myProxy.prop2 = "The property value"; trace(myProxy.prop2); // Outputs "The property value"
What if I would like to have both the functionalities? DynaObjectProxy allows exactly this: you can both wrap a class instance and create new properties keeping all the new properties bindable at the same time.
Now we can start looking through the DynaObjectProxy source code and later we’ll see how it can be used with an example. Read the rest of this entry »

Recent Comments