I have an established pattern for lazy loading data from a server via AMF.
private var _XeventDispatched:Boolean;
private var _X:ArrayCollection;
public function get X():ArrayCollection{
if(!_XeventDispatched && (_X==null || _X.length==0)){
var evt:Event = new Event();//whatever event is need for this data member
dispatcher.dispatchEvent(evt);
_XeventDispatched = true;
}
return _X;
}
public function set X(ac:ArrayCollection):void{
return _X;
}
This way the data is not loaded from the server until it is needed. (I'm using the Mate framework by the way, so when a UI is instanciated, and the injectors fire, they call this get method in the data manager class.)
What I'd like to do is create some kind of Metadata tag, similar to [Bindable] that will add the above methods in place of a public property.
[LazyLoaded(eventName="com.myCompany.LoadX")]
public var X:ArrayCollection;
Does the compiler have any hooks for this type of extension? It would save a lot of boiler plate code that is hard to read.