MACROMEDIA FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual de usuario Pagina 115

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 184
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 114
Using function listeners 115
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
addEventListener() method. The
listener argument of the
addEventListener() method was of type Object, which also
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>
Vista de pagina 114
1 2 ... 110 111 112 113 114 115 116 117 118 119 120 ... 183 184

Comentarios a estos manuales

Sin comentarios