O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Event Listeners and the Event Flow

As we've just seen, during an event dispatch targeted at a given display object, that object's display ancestors receive event notification during the capture phase and potentially also during the bubbling phase (if the event is a bubbling event). Accordingly, when we register a listener with an event target's ancestor we must indicate whether that listener should be triggered during the capture phase or the bubbling phase.

To register a listener with an event target's ancestor for the capture phase of an event dispatch, we set addEventListener( )'s third parameter, useCapture, to true, as in:

theAncestor.addEventListener(theEvent, theListener, true)

The preceding line of code causes theListener( ) to be executed whenever ActionScript dispatches theEvent targeted at one of theAncestor's descendants, before that descendant receives notification of the event.

To register a listener with an event target's ancestor for the bubbling phase of an event dispatch, we set addEventListener( )'s third parameter to false, as in:

theAncestor.addEventListener(theEvent, theListener, false)

Alternatively, because useCapture's default value is false, we can simply omit the useCapture argument, as in:

theAncestor.addEventListener(theEvent, theListener)

The preceding line of code causes theListener( ) to be executed whenever ActionScript dispatches theEvent targeted at one of theAncestor's descendants, after that descendant receives notification of the event.

Tip

For brevity ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required