User Guide

Working with events 109
With simple MXML components, you can define event listeners in both places, and both
event listeners process the event. However, the event listeners defined within the component
execute before any listeners defined in the application.
Creating custom events
All MXML components can dispatch events, either those inherited by the components from
their superclasses, or new events that you define within your components. When you are
developing MXML components, you can add your own event types.
In this example, you define a new component called TextAreaEnabled.mxml that uses a
<mx:TextArea> tag as its root tag. This component also defines a new property called
enableTA that users set to true to enable text input or to false to disable input.
The setter method dispatches a new event type, called
enableChanged, when the value of the
enableTA variable changes. The [Event] metadata tag identifies the event to the MXML
compiler so that the file referencing the component can use the new property. For more
information on using the
[Event] metadata keyword, see Chapter 5, “Using Metadata Tags
in Custom Components,” on page 45.
The syntax for the
[Event] metadata tag is as follows:
<mx:Metadata>
[Event(name="eventName", type="eventType")]
</mx:Metadata>