Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 143

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

Advertisement

You might define some custom events that are used internally by your component, and are
not intended to be recognized by the other components. For example, the following
component defines a custom event, dispatches it, and handles it all within the component:
package myComponents
{
import mx.controls.TextArea;
import flash.events.Event;
public class ModalText extends TextArea {
public function ModalText() {
super();
// Register event listener.
addEventListener("enableChanged", enableChangedListener);
}
public function enableInput(value:Boolean):void {
// Method body.
// Dispatch event.
dispatchEvent(new Event("enableChanged"));
}
private function enableChangedListener(eventObj:Event):void {
// Handle event.
}
}
}
In this example, the public method
the control. When you call the
method to dispatch the
dispatchEvent()
method has the following signature:
dispatchEvent(eventObj)
The
argument is the event object that describes the event.
eventObj
If you want an MXML component to be able to register a listener for the event, you must
make the event known to the Flex compiler by using the
public event that your custom component dispatches, you add an
before the class definition that defines that event; for example:
[Event(name="enableChanged", type="flash.events.Event")]
public class ModalText extends TextArea {
...
}
enableInput()
method, the component uses the
enableInput()
enableChanged
Defining events in ActionScript components
lets the user enable or disable input to
event. The
dispatchEvent()
metadata tag. For each
[Event]
[Event]
metadata keyword
143

Advertisement

Table of Contents
loading

Table of Contents