Earlier we learned how to use the addChild( ) and addChildAt( ) methods to add a new display child to a DisplayObjectContainer object. Recall the general code:
// The addChild() method
newChild) // The addChildAt() method
We also learned that existing child display objects can be removed from a DisplayObjectContainer object via the removeChild( ) and removeChildAt( ) methods. Again, recall the following general code:
// The removeChild() method
childToRemove) // The removeChildAt() method
Finally, we learned that an existing child display object can be removed from a container by moving that child to another container via either addChild( ) and addChildAt( ). Here's the code:
child) // Remove
someContainerby moving it to
Each of these child additions and removals is accompanied by a
built-in Flash runtime event—either
Event.REMOVED. The following three sections
explore how these two events are used in display programming.
The following sections require a good understanding of ActionScript's hierarchical event dispatch system, as discussed in Chapter 21. If you are not yet thoroughly familiar with hierarchical event dispatch, read Chapter 21 before continuing with the following sections.