Using The Eventdispatcher Class - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

You must also change your code if you created a custom event handler class and defined a
method that listened for all events. Flex implicitly registered this method as a
handleEvent()
handler for all events. Functions named
as they did in Flex 1.x.
For example, if in your application you registered the custom listener with the
addEventListener()
public var myListener:MyEventListener = new MyEventListener();
b1.addEventListener("click", myListener);
You now explicitly register the custom listener's
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()
longer construct an event using an Object like
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);
}
116
Events
handleEvent()
method, as follows:
method now requires an argument of type Event, so you can no
no longer catch all events by default
method for each event you
handleEvent()
{ type: "click" }
. You must now do the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents