Flex/AIR: DynamicEvent

Applies to: Adobe Flex & AIR

A DynamicEvent is a type of custom event in Flex that is easier and quicker to set up than the full-blown approach. By applying the latter method, you normally go through the following steps:

  1. Define a subclass from flash.events.Event
  2. Make the event available to other ActionScript (through addEventListenter()) components or MXML components (using the [Event] metatag)
  3. Dispatch the event, using dispatchEvent()

Full documentation on custom events can be found in Adobe’s LiveDocs, here.

Generally one uses the above approach when you need to pass arguments to the code that’s targeted by the event. When you don’t require this, however, you can opt for the DynamicEvent. It’s not necessary to go through the whole rigamarole of subclassing; all you need is a name for the event, like so:

var yourEvent:DynamicEvent = new DynamicEvent("yourEventName", true);
dispatchEvent(yourEvent);

The second argument set to true means the event will bubble.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s