Or, Non Visual Action Script Components that are implemented in mxml. I have several components that I use on a day to day basis that are non visual in nature and that I want to implement in mxml. I need them to have an « id » and fire off some common events, particularly creationComplete invents. Until recently my hack had been just to extend UIComponent, but knowing this was not ideal at all for so many reasons (they would take up space on the page, doh!) I’m sure ya’ll can tell me about, I finally took the time to figure out how do create a non visual component and dispatch the proper events.
Have your object extend EventDispatcher and implement IMXMLObject. Then all you have to do is fire off the events you want when you want them. In my original use case I wanted to know the creationComplete event and so I implemented something similar to the following, but you can add all sorts of events that you might otherwise use with mxml objects.
import
flash.events.EventDispatcher; import mx.core.IMXMLObject; import mx.events.FlexEvent;[
Event(name="creationComplete", type="mx.events.FlexEvent")] public class NonVisualComponent extends EventDispatcher implements IMXMLObject{
public function initialized(document:Object, id:String):void
{
this.document = document; this.id = id;
this.dispatchEvent( new FlexEvent("creationComplete",true));
}
public function NonVisualComponent():void
{
super();
}
public var document : Object; public var id:String;
Nice one! I always extended UIComponent too; thanks for the post!!!
Posted by: JesterXL | February 04, 2008 at 08:52 PM