Dispatching Custom Events - Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

Dispatching custom events

Flex defines many of the most common events, such as the
control, however, your application may require that you create events. In your custom Flex
components, you can dispatch any of the predefined events inherited by the component from
its superclass, and dispatch new events that you define within the component.
To dispatch a new event from your custom component, you must do the following:
(Optional) Create a subclass from the
1.
describes the event object. For more information, see
class" on page
38.
(Optional) Use the
2.
compiler recognizes it. For more information, see
on page
40.
Dispatch the event using the
3.
"Dispatching an event" on page
Creating a subclass from the Event class
All events use an event object to transmit information about the event to the event listener,
where the base class for all event objects is the
custom event, you can dispatch an event object of type Event, or you can create a subclass of
the Event class to dispatch an event object of a different type. You typically create a subclass of
the Event class when your event requires you to add information to the event object, such as a
new property to hold information that the event listener requires.
For example, the event objects associated with the Flex
, which identifies the node of the Tree control associated with the event. To support the
node
property, the Tree control dispatches event objects of type TreeEvent, a subclass of the
node
Event class.
Within your subclass of the Event class, you can add properties, add methods, set the value of
an inherited property, or override methods inherited from the Event class. For example, you
might want to set the
which is inherited from the Event class.
You are required to override the
method returns a cloned copy of the event object by setting the
properties in the clone. Typically, you define the
created with the
new
38
Creating Custom Events
metadata tag to make the event public so that the MXML
[Event]
dispatchEvent()
41.
property to
bubbles
Event.clone()
operator.
click
flash.events.Event
class to create an event class that
"Creating a subclass from the Event
"Using the Event metadata tag"
method. For more information, see
flash.events.Event
Tree
control include a property named
to override the default setting of
true
method in your subclass. The
method to return an event instance
clone()
event for the
Button
class. When you define a
false
clone()
property and any new
type
,

Advertisement

Table of Contents
loading

Table of Contents