User Guide
40 Creating Custom Events
Using the Event metadata tag
You use the [Event] metadata tag to define events dispatched by a component so that the
Flex compiler can recognize them as MXML tag attributes in an MXML file. You add the
[Event] metadata tag in one of the following locations:
ActionScript components Above the class definition, but within the package definition, so
that the events are bound to the class and not a particular member of the class.
MXML components In the <mx:Metadata> tag of an MXML file.
The Event metadata keyword has the following syntax:
[Event(name=”eventName”, type=”package.eventType”)]
The eventName argument specifies the name, including the package, of the event. The
eventType argument specifies the class that defines the event.
The following example identifies the
enableChange event as an event that an ActionScript
component can dispatch:
[Event(name="enableChange", type="myEvents.EnableChangeEvent")]
public class MyComponent extends TextArea
{
...
}
The following example shows the [Event] metadata tag within the <mx:Metadata> tag of an
MXML file:
<?xml version="1.0"?>
<!-- events\myComponents\MyButton.mxml -->
<mx:Button xmlns:mx="http://www.adobe.com/2006/mxml"
click="dispatchEvent(new EnableChangeEvent('enableChanged'));">
<mx:Script>
<![CDATA[
import myEvents.EnableChangeEvent;
]]>
</mx:Script>
<mx:Metadata>
[Event(name="enableChanged", type="myEvents.EnableChangeEvent")]
</mx:Metadata>
</mx:Button>