« The label on my Value Object | Main | dataProvider, setForm(), or whateva »

February 04, 2008

Who wants to see Non Visual Components anyways.

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;

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c046453ef00e5501426a78833

Listed below are links to weblogs that reference Who wants to see Non Visual Components anyways. :

Comments

Nice one! I always extended UIComponent too; thanks for the post!!!

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment