Using Static Constants - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

If you try to call another method on the target (for example, the
returns an error. The
DisplayObject. Therefore, you must cast event.target to UIComponent before calling the
method, as the following example shows:
getStyle()
function myEventListener(e:Event) {
UIComponent(e.target).getStyle("color");
}
If you use the
target
event, you should consider changing the
property supports event bubbling and capturing, which are new in Flex 2.
currentTarget
During these phases, the event is actually being handled by the target's parent containers. The
target still refers to the dispatcher of the event, but the
control is currently processing a bubbling or capture event.
For example, if you have
might be one of the rows, but
is generally what you would expect.
Another example is what occurs when you assign a mouseDown handler on a TextInput
control. Actually, the TextField class that is inside the TextInput control dispatches the event
(depending on where the user clicked), so the TextField control, not the TextInput control, is
the
. However, the TextInput control is the
target
attached the handler.
Most controls have internal subcomponents that are often the target for mouse events.

Using static constants

Use static constants to represent event types; for example, use
, as the following example shows:
"click"
addEventListener("click", myClickListener); // Flex 1.5
addEventListener(MouseEvent.CLICK, myClickListener); // Flex 2
Change the following:
switch (event.type) {
case "click":
...
}
To this:
switch (event.type) {
case MouseEvent.CLICK:
...
}
114
Events
method is a method of UIComponent, a subclass of
getStyle()
property of the Event object to determine which control triggered the
target
<mx:List click="..."/>
event.currentTarget
getStyle()
property to
currentTarget
currentTarget
, inside the click handler
is a reference to the List control, which
if that is where you
currentTarget
MouseEvent.CLICK
method), Flex
. The
refers to whatever
event.target
rather than

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents