Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 111

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

Advertisement

The following main application includes TextAreaEnabled.mxml and defines an event listener
for the
enableChanged
<?xml version="1.0"?>
<!-- mxmlAdvanced/MainTextAreaEnable.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<mx:Script>
<![CDATA[
import flash.events.Event;
import myComponents.TextAreaEnabled;
public function handleEnableChangeEvent(eventObj:Event):void {
var tempTA:TextAreaEnabled =
if (tempTA.enableTA) {
else {
}
]]>
</mx:Script>
<MyComp:TextAreaEnabled id="myTA" enableTA="false"
enableChanged="handleEnableChangeEvent(event);" />
<mx:Button id="myButton" label="Click to enable"
click="myTA.enableTA=!myTA.enableTA;" />
</mx:Application>
If you do not use the
event, the MXML compiler generates an error message when you reference
enableChanged
the event name in an MXML file. Any component can register an event listener for the event
in ActionScript using the
metadata tag.
You can also create and dispatch events that use an event object of a type other than that
defined by the
Event
contains new properties so that you can pass those properties back to the referencing file. To
do so, you create a subclass of the Event class to define your new event object. For information
on creating custom event classes, see
event:
eventObj.currentTarget as TextAreaEnabled;
myButton.label="Click to disable";
}
myButton.label="Click to enable";
}
metadata tag in the custom component file to define the
[Event]
addEventListener()
class. For example, you might want to create an event object that
Chapter 4, "Creating Custom Events," on page
method, even if you omit the
Working with events
[Event]
35.
111

Advertisement

Table of Contents
loading

Table of Contents