Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 41

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

Advertisement

Once defined using the
the following example shows:
<?xml version="1.0"?>
<!-- events/MainEventApp.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*" >
<mx:Script>
<![CDATA[
import myEvents.EnableChangeEvent;
public function
enableChangedListener(eventObj:EnableChangeEvent):void {
}
]]>
</mx:Script>
<MyComp:MyButton enableChanged="myTA.text='got event';" />
<mx:TextArea id="myTA" />
</mx:Application>
If you do not identify an event with the
error if you try to use the event name in MXML. The metadata for events is inherited from
the superclass, however, so you do not need to tag events that are already defined with the
metadata tag in the superclass.
[Event]
Dispatching an event
You use the
dispatchEvent()
has the following signature:
public dispatchEvent(event:Event):Boolean
This method requires an argument of type Event, which is the event object. The
method initializes the
dispatchEvent()
to the component dispatching the event.
You can create an event object and dispatch the event in a single statement, as the following
example shows:
dispatchEvent(new Event("click"));
You can also create an event object, initialize it, and then dispatch it, as the following example
shows:
var eventObj:EnableChangeEvent = new EnableChangeEvent("enableChange");
metadata tag, you can refer to the event in an MXML file, as
[Event]
// Handle event.
[Event]
method to dispatch an event. The
target
metadata tag, the compiler generates an
dispatchEvent()
property of the event object with a reference
Dispatching custom events
method
41

Advertisement

Table of Contents
loading

Table of Contents