Game Development Reference
Events aren't broadcast to every object in the program at the same time, however. They either travel
up or down through the hierarchy of objects. You can listen to events at any point in this journey.
If an event is set to bubble, it means that the event travels up through the hierarchy. It starts with the
child object and then informs the parent object. If other objects want to listen to that event, they have
to do it by attaching their event listeners to the parent object. Often, that object will be op]ca, which
is the common parent of all display objects. Figure 10-23 illustrates a simple example.
2. Events bubble up to
the parent container.
3. Objects can listen to
events by attaching a
listener to the parent
1. An object dispatches an event.
4. Listening objects can create an event handler
to perform actions when the event happens. They
can access the object that called the event by using
the event's target property.
Figure 10-23. Objects can listen to bubbling events from other objects by attaching event listeners to a common
parent object, such as the stage.
The `eol]p_dArajp method has one argument, which is called the event constructor :
The event constructor creates the event. Events can be made to bubble by setting the second argu-
ment in the event constructor to pnqa:
jasArajp$arajpJ]ia( pnqa %
If you change it to b]hoa or leave it out entirely, the event doesn't bubble.