13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Handling ev<strong>en</strong>ts<br />

If a user clicks on Child1 Node, Flash Player or AIR dispatches an ev<strong>en</strong>t object into the ev<strong>en</strong>t flow. As the following<br />

image shows, the object’s journey starts at Stage, moves down to Par<strong>en</strong>t Node, th<strong>en</strong> moves to Child1 Node, and<br />

th<strong>en</strong> “bubbles” back up to Stage, moving through Par<strong>en</strong>t Node again on its journey back to Stage.<br />

Capture<br />

Phase<br />

Stage<br />

Par<strong>en</strong>t Node<br />

Child1 Node Child2 Node<br />

Target Phase<br />

In this example, the capture phase comprises Stage and Par<strong>en</strong>t Node during the initial downward journey. The target<br />

phase comprises the time sp<strong>en</strong>t at Child1 Node. The bubbling phase comprises Par<strong>en</strong>t Node and Stage as they are<br />

<strong>en</strong>countered during the upward journey back to the root node.<br />

The ev<strong>en</strong>t flow contributes to a more powerful ev<strong>en</strong>t-handling system than that previously available to ActionScript<br />

programmers. In previous versions of ActionScript, the ev<strong>en</strong>t flow does not exist, which means that ev<strong>en</strong>t list<strong>en</strong>ers can<br />

be added only to the object that g<strong>en</strong>erates the ev<strong>en</strong>t. In ActionScript 3.0, you can add ev<strong>en</strong>t list<strong>en</strong>ers not only to a target<br />

node, but also to any node along the ev<strong>en</strong>t flow.<br />

The ability to add ev<strong>en</strong>t list<strong>en</strong>ers along the ev<strong>en</strong>t flow is useful wh<strong>en</strong> a user interface compon<strong>en</strong>t comprises more than<br />

one object. For example, a button object oft<strong>en</strong> contains a text object that serves as the button’s label. Without the ability<br />

to add a list<strong>en</strong>er to the ev<strong>en</strong>t flow, you would have to add a list<strong>en</strong>er to both the button object and the text object to<br />

<strong>en</strong>sure that you receive notification about click ev<strong>en</strong>ts that occur anywhere on the button. The exist<strong>en</strong>ce of the ev<strong>en</strong>t<br />

flow, however, allows you to place a single ev<strong>en</strong>t list<strong>en</strong>er on the button object that handles click ev<strong>en</strong>ts that occur either<br />

on the text object or on the areas of the button object that are not obscured by the text object.<br />

Not every ev<strong>en</strong>t object, however, participates in all three phases of the ev<strong>en</strong>t flow. Some types of ev<strong>en</strong>ts, such as the<br />

<strong>en</strong>terFrame and init ev<strong>en</strong>t types, are dispatched directly to the target node and participate in neither the capture<br />

phase nor the bubbling phase. Other ev<strong>en</strong>ts may target objects that are not on the display list, such as ev<strong>en</strong>ts dispatched<br />

to an instance of the Socket class. These ev<strong>en</strong>t objects will also flow directly to the target object, without participating<br />

in the capture and bubbling phases.<br />

To find out how a particular ev<strong>en</strong>t type behaves, you can either check the API docum<strong>en</strong>tation or examine the ev<strong>en</strong>t<br />

object's properties. Examining the ev<strong>en</strong>t object’s properties is described in the following section.<br />

Ev<strong>en</strong>t objects<br />

Bubbling<br />

Phase<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Ev<strong>en</strong>t objects serve two main purposes in the new ev<strong>en</strong>t-handling system. First, ev<strong>en</strong>t objects repres<strong>en</strong>t actual ev<strong>en</strong>ts<br />

by storing information about specific ev<strong>en</strong>ts in a set of properties. Second, ev<strong>en</strong>t objects contain a set of methods that<br />

allow you to manipulate ev<strong>en</strong>t objects and affect the behavior of the ev<strong>en</strong>t-handling system.<br />

To facilitate access to these properties and methods, the Flash Player API defines an Ev<strong>en</strong>t class that serves as the base<br />

class for all ev<strong>en</strong>t objects. The Ev<strong>en</strong>t class defines a fundam<strong>en</strong>tal set of properties and methods that are common to all<br />

ev<strong>en</strong>t objects.<br />

Last updated 6/6/2012<br />

130

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!