Macromedia flex 2 Manual
142
Creating Simple Visual Components in ActionScript
Your custom component can also define event listeners within the component itself to handle
the events internally. For example,
the events internally. For example,
defined event listeners for the
keyDown
and
creationComplete
events within the body of the
component. This allows the component to handle those events internally.
The example used the
creationComplete
event to access the default
fontSize
property of
the component. You could not access this property in the constructor itself because Flex does
not define it until after the component is created. For more information on the initialization
order of a component, see
not define it until after the component is created. For more information on the initialization
order of a component, see
.
Dispatching custom events
Your ActionScript component can define custom events and use the predefined events. You
use custom events to support data binding, to respond to user interactions, or to trigger
actions by your component. For an example that uses events to support data binding, see
use custom events to support data binding, to respond to user interactions, or to trigger
actions by your component. For an example that uses events to support data binding, see
.
For each custom event dispatched by your component, you must do the following:
1.
Create an
Event
object describing the event.
2.
(Optional) use the
[Event]
metadata tag to make the event public so that other
components can listen for it.
3.
Dispatch the event by using the
dispatchEvent()
method.
To add information to the event object, you define a subclass of the flash.events.Event class to
represent the event object. For more information on creating custom event classes, see
represent the event object. For more information on creating custom event classes, see
NO
TE
Even though you define event listeners for the events in the component itself, your
application can also register listeners for those events. The event listeners defined within
the component execute before any listeners defined in the application.
application can also register listeners for those events. The event listeners defined within
the component execute before any listeners defined in the application.