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 Priority and the Event Flow

When an event listener registers with an object in a display hierarchy, the priority parameter affects the trigger order of listeners registered with that object only. The priority parameter does not, and cannot, alter the order in which objects in the event flow are notified.

Tip

There is no way to force a listener of one object in the event flow to be triggered before or after a listener of another object in the same event flow.

For example, suppose a Sprite object contains a TextField object. The Sprite object registers a MouseEvent.CLICK listener, spriteClickListener( ), with useCapture set to false and priority set to 2:

theSprite.addEventListener(MouseEvent.CLICK, spriteClickListener, false, 2)

Likewise, the TextField object registers a MouseEvent.CLICK listener, textClickListener( ), with useCapture set to false and priority set to 1:

theTextField.addEventListener(MouseEvent.CLICK, textClickListener, false, 1)

When the user clicks the TextField object, the Flash runtime dispatches a MouseEvent.CLICK event targeted at the TextField object. In response, textClickListener( ) is triggered during the target phase, before spriteClickListener( ), which is triggered during the bubbling phase. The two event listeners are triggered according to the order of the event flow, even though spriteClickListener( ) registered with a higher priority than textClickListener( ).

For more information on event priority, see Chapter 12.

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