Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 170

Programming actionscript 3.0
Table of Contents

Advertisement

You can use the
method to verify the layer order of the display objects. The
getChildAt()
method returns child objects of a container based on the index number you
getChildAt()
pass it. For example, the following code reveals names of display objects at different positions
in the child list of the
DisplayObjectContainer object:
container
trace(container.getChildAt(0).name); // ball_A
trace(container.getChildAt(1).name); // ball_C
trace(container.getChildAt(2).name); // ball_B
If you remove a display object from the parent container's child list, the higher elements on
the list each move down a position in the child index. For example, continuing with the
previous code, the following code shows how the display object that was at position 2 in the
DisplayObjectContainer moves to position 1 if a display object that is lower in
container
the child list is removed:
container.removeChild(ball_C);
trace(container.getChildAt(0).name); // ball_A
trace(container.getChildAt(1).name); // ball_B
The
and
methods do not delete a display object instance
removeChild()
removeChildAt()
entirely. They simply remove it from the child list of the container. The instance can still be
referenced by another variable. (Use the
operator to completely remove an object.)
delete
Because a display object has only one parent container, you can add an instance of a display
object to only one display object container. For example, the following code shows that the
display object
can exist in only one container (in this case, a Sprite, which extends the
tf1
DisplayObjectContainer class):
tf1:TextField = new TextField();
tf2:TextField = new TextField();
tf1.name = "text 1";
tf2.name = "text 2";
container1:Sprite = new Sprite();
container2:Sprite = new Sprite();
container1.addChild(tf1);
container1.addChild(tf2);
container2.addChild(tf1);
trace(container1.numChildren); // 1
trace(container1.getChildAt(0).name); // text 2
trace(container2.numChildren); // 1
trace(container2.getChildAt(0).name); // text 1
If you add a display object that is contained in one display object container to another display
object container, it is removed from the first display object container's child list.
170
Display Programming

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents