Game Development Reference
In-Depth Information
can modify the listeners in the Document class to account for all
three event phases:
addEventListener(Game.GAME_START, gameStart, true, 0, true);
game.addEventListener(Game.GAME_START, gameStart, false, 0,
addEventListener(Game.GAME_START, gameStart, false, 0, true);
Note the subtle differences between how the listeners are
added. The capture and bubbling listeners are identical, except for
the useCapture parameter, and the target listener is attached to the
game object directly. There are few times when you
d probably
use all of these listener types at once. I almost always listen at the
target phase because I usually know which object I need to receive
events and which don
t matter. One scenario where it is very help-
ful, though, is when you need to stop an event from being
Event Propagation and Cancellation
By default, events, particularly those in DisplayObjects, will move
through their hierarchy uninterrupted, notifying each listener in
the chain as the event reaches it. However, there might be some
scenarios where you would want to stop certain events from
reaching their destination. A common example is with mouse
input. Say you had an application or a game with a side panel
containing some buttons and other information. If you were dis-
playing a message and wanted to disable input to the panel while
the message was being shown, you could tell the panel to disable
itself, which would in turn disable each of the buttons. However,
canceling events.
When one of the buttons in the panel is clicked on by the
mouse, for example, it generates an event (specifically, a Mouse-
Event) that moves through each display list level until it reaches
the object that was clicked. If you listen for that event during the
capture phase in some parent object of the panel, you can stop
that event from proceeding any further and ever reaching its desti-
nation. You do this through the use of a couple of methods of
event objects: stopPropagation and stopImmediatePropagation .
They both do virtually the same thing but with minor differences.
The former stops any objects further down the display chain from
receiving the event. The latter stops those objects, as well as any
other listeners, in the current DisplayObject.
Search Nedrilad ::

Custom Search