Managing the Stacking Order
As mentioned earlier, when you add display objects to the Display List, it's like laying cards on a card table. The first card appears on the table, and the next card is placed on top of it (Figure 14-12). Each card placed on the table is at a specific position in the stack. Like a lot of programming lists, the Display List position index begins at 0. So the first object placed in a display object container is at position 0. The second object is placed at position 1, and so forth. The position is known as the index, and it's represented by a number that's an int type (integer). As the display objects in your Flash animation become more numerous, it's harder to keep track of them. There are times when it might be easier for you, the ActionScripter, to identify an object by its position in the stack rather than by its instance name. For example, you might have a card game where you want to deal the top five cards in the deck. In this case, the cards' names don't matter as much as their position in the deck.
Figure 14-12. The code in the box on page 486 places cards on the main timeline display object container. Card 1 was placed first, then Card 2, and so forth. Trace statements show that Card 1 is at position 0, Card 2 is at position 1, and so forth.
Adding Display Objects by Index Position
Just as display object containers have methods for working with child ...
Get Flash CS5: The Missing Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.