Using Function Listeners - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

To find the appropriate static constant for your event type, see the events section of the
control's entry in Adobe Flex 2 Language Reference.

Using function listeners

When migrating, convert all object event listeners to function event listeners. You can no
longer pass an object as the second parameter to the
listener argument of the
accepted a Function, but is now of type Function. If you try to pass an object listener, Flex
reports an error.
For example, if you had the following:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
creationComplete="createHandler()">
<mx:Script>
import mx.core.Alert;
function createHandler() {
var myListener = new Object();
myListener.click = function(event) {
Alert.show("This is a log message");
}
myButton.addEventListener("click", myListener);
trace("Added listener");
}
</mx:Script>
<mx:Button label="Click Me" id="myButton"/>
</mx:Application>
Convert it to the following:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="createHandler()">
<mx:Script>
import mx.controls.Alert;
private function createHandler():void {
trace("Added listener");
button1.addEventListener(MouseEvent.CLICK, myClickHandler);
}
private function myClickHandler(event:MouseEvent):void {
Alert.show("This is a log message");
}
</mx:Script>
<mx:Button label="Click Me" id="button1"/>
</mx:Application>
addEventListener()
addEventListener()
method was of type Object, which also
Using function listeners
method. The
115

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents