flash display_list_stacking_objects
Stacking management of display objects
To modify the superimposing of child objects in a DisplayObjectContainer, we have the setChildIndex method. Here is its signature:
public function setChildIndex(child:DisplayObject, index:int):void
The setChildIndex method is called on the child object container to be manipulated. If the index is negative or doesn’t correspond to any occupied index, its calling raises a RangeError exception type.
To really understand how this method works, let’s look at it closer.
Open a new Flash CS3 document and create two different shaped clips. Superimpose them like this:
Give them occurrence names such as myCircle and myRectangle. We want to pass the myCircle clip in front of the myRectangle clip. We can easily see that the latter is positioned at index 1 and the first at index 0.
To place the circle on index 1 we pass the setChildIndex method while specifying the destination index. On an AS layer we define the following code:
setChildIndex( myCircle, 1 );
The circle is temporarily deleted from the list making our rectangle drop to index 0 to leave room for our circle at index 1. The latter is therefore placed in the foreground as shown here:
The change of index of a DisplayObject is divided into many phases. Let’s take the example of 8 graphic objects. We want to pas the DisplayObject of index 1 to index 6:
If we don’t know the name of graphic objects we can write:
setChildIndex ( getChildAt ( 1 ), 6 );
We get the DisplayObject at index 1 to pass it to index 6. When the latter is taken from its original index the superior DisplayObjects will therefore drop an index, exactly as if we take a plate from a stack of plates. This is the behavior that we have previously discussed called depth collapse.
Here is the result of a change in index of the DisplayObject:
Let’s this time say that we want to move a DisplayObject from index 5 to index 0:
To proceed with this move in the child object list we write:
setChildIndex ( myDisplayObject, 0 );
When a DisplayObject is moved to an inferior index to its original index, the intermediary graphic objects don’t collapse but climb an index. The previous code provokes therefore the following organisation:
With the use of the setChildIndex method, the intermediary graphic objects including the original and final index can be pushed or dropped a level.
Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42








