Migrating The Event Object - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

Migrating the Event object

This section describes migration issues related to accessing the Event object.
Using the Event object
The Event object is no longer of type Object. It is now of type flash.events.Event. Specify a
stricter type in functions, as follows:
private function eventHandler(event:Object):Void { // Flex 1.5
private function eventHandler(event:Event):void { // Flex 2
You should also now cast the
in an event handler to an appropriate type to
event.target
avoid compile-time warnings. The new code should specify the stricter event type as a
function parameter, as the following example shows:
private function doDragExit(event:DragEvent):void {
event.target.hideDropFeedback(event);
}
If you assign the target to a stronger-typed variable, you must cast; for example:
var clickTarget:Button = Button(event.target);
When using the Event object, you are encouraged to use the most strict type possible. This
lets you access properties that are specific to the target type. For example, in a mouse click
listener, you should declare the Event of type MouseEvent rather than of type Event, as
follows:
private function myClickHandler(event:MouseEvent):void { ... }
If you use Event as the type, rather than MouseEvent, you do not have access to any properties
that are specific to the MouseEvent class.
Using the target property
Calling methods and accessing properties on the target can be confusing. The default type of
Event.target is Object. Because ActionScript is strongly typed, you can call
only if you cast the
to an object type that
event.target.methodName()
event.target
defines that
. The same applies for properties. You can access
methodName
only if you define
on the new type.
event.target.property
property
Migrating the Event object
113

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents