Lately I stumpled across a mysterious metatag in different AS3 classes that looked like this:

[Event(name="checked", type="CheckboxEvent")]

As I am relatively new to AS3 and Flash Builder I have never seen this piece of code before. Have you ever wondered why and how to use this tags?

The event metatags are placed right before the class definition and are used to tell the compiler which events can be dispatched in this class. This is pretty useful to get code completion from the Flash Builder. Here is an example:

If you are developing an ActionScript component, e.g. a simple checkbox you may need custom events (extending, too. Let us call these two classes “” and “”. The event class can contain several constants to use as events.

public static const CHECKED :String = 'checked';
public static const UNCHECKED :String = 'unchecked';

Now you can use the defined events inside your Checkbox-class like this:

dispatchEvent( new CheckboxEvent( CheckboxEvent.CHECKED ) );

And now you can see the real advantage of event metags. Try to instantiate your checkbox and add an event listener. Without the event metatag there is no code completion.

no code completion without event metatags in Flash Builder

After that go back to the Checkbox-class and add the event metatags. The name attribute has to match to the strings inside your event constants (e.g. “checked”) and the type attribute represents your custom event-class (in this case “CheckboxEvent”). Now the code completion looks like this:

code completion with event metatags in Flash Builder

This looks much better. Your two custom events are listet on topof the events-list – just because of the two event metatags inside the Checkbox-class.