Step 4: Update Events - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

Step 4: Update events

The Event model changed in Flex 2. However, you can migrate most event handlers with
minimal effort. This section describes the most popular changes that you must make to your
event handling code. For more information about migrating events, see
Chapter 6, "Events,"
on page
111.
Specify types
Events are now more strongly typed than in Flex 1.x. As a result, you should specify the object
type in the event listener function. For example, previously you could write the following:
function myListener(event) { var s = event.type; }
Now, you must specify an event object in the function's signature; for example:
private function myListener(event:Event):void { var s = event.type; }
Where possible, make the events as specific as possible. If the previous example was a listener
for click events, specify a MouseEvent as the type:
private function myListener(event:MouseEvent):void { ... }
Dispatch custom events
When you dispatch custom events, you must declare a new Event object rather than use a
generic object; for example:
click="dispatchEvent(new Event('checkOut'))"
Remove delegates
You are no longer required to wrap a listener function with a Delegate to maintain application
scope. You can remove the Delegate from the following line:
b1.addEventListener("click", mx.utils.Delegate.create(this,myListener));
So the line appears as follows:
b1.addEventListener(MouseEvent.CLICK, myListener);
16
Getting Started

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents