
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 listener’s 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 player’s 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);
}
Comentários a estes Manuais