MACROMEDIA FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manuale Utente Pagina 116

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 184
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 115
116 Events
You must also change your code if you created a custom event handler class and defined a
handleEvent() method that listened for all events. Flex implicitly registered this method as a
handler for all events. Functions named
handleEvent() no longer catch all events by default
as they did in Flex 1.x.
For example, if in your application you registered the custom listener with the
addEventListener() method, as follows:
public var myListener:MyEventListener = new MyEventListener();
b1.addEventListener("click", myListener);
You now explicitly register the custom listeners handleEvent() method for each event you
want to handle, as follows:
public var myListener:MyEventListener = new MyEventListener();
b1.addEventListener(MouseEvent.CLICK, myListener.handleEvent);
Using the EventDispatcher class
The UIComponent class now inherits from the players EventDispatcher class. As a result, you
no longer need to mix in the EventDispatcher class when creating new components.
The
dispatchEvent() method now requires an argument of type Event, so you can no
longer construct an event using an Object like
{ type: "click" }. You must now do the
following instead:
dispatchEvent(new MouseEvent(MouseEvent.CLICK));
To dispatch an event from a custom component, you can do the following:
Flex 1.x:
<mx:CustomPanel mouseDown="dispatchEvent({type: 'resizeEvent', size:
'small'})">
Flex 2:
private function mouseDownHandler(event:MouseEvent):void {
var resizePanelEvent:ResizePanelEvent = new
ResizePanelEvent(ResizePanelEvent.RESIZE);
resizePanelEvent resizePanelEvent.size = "small";
dispatchEvent(event);
}
Vedere la pagina 115
1 2 ... 111 112 113 114 115 116 117 118 119 120 121 ... 183 184

Commenti su questo manuale

Nessun commento