apache-flexeventsdynamic-class

In Flex, how do I know when the properties of a dynamic object change?


I have a dynamic class that serves as a storage container for configuration settings. The settings are variables of that class and it has methods to read from and write to a configuration file, database etc. Now I want to trigger writing to the persistant storage whenever a class variable is changed. As the variables are added dynamically at runtime, I can't use get/set methods, also, if I could, that would lead to a lot of boilerplate code.

How can I have an event triggered for changing properties of my class?


Solution

  • You can subclass this class of yours from mx.utils.Proxy. It allows you to have the object be dynamic yet still be able to write some custom code that runs whenever properties are accessed (similarly to getters and setters -- see getProperty() and setProperty().)