User Guide
194 Display Programming
Rearranging display object layering
The user interface for the application includes buttons labeled Move Back, Move Down,
Move Up, and Move to Front. When the user clicks one of these buttons, the application calls
the corresponding method of the DrawingCanvas class:
moveToBack(), moveDown(),
moveUp(), or moveToFront(). For example, the moveToBack() method includes the
following code:
public function moveToBack(shape:GeometricSprite):void
{
var index:int = this.getChildIndex(shape);
if (index > 0)
{
this.setChildIndex(shape, 0);
}
}
The method uses the setChildIndex() method (inherited from the DisplayObjectContainer
class) to position the display object in index position 0 in the child list of the DrawingCanvas
instance (
this).
The
moveDown() method works similarly, except that it decrements the index position of the
display object by 1 in the child list of the DrawingCanvas instance:
public function moveDown(shape:GeometricSprite):void
{
var index:int = this.getChildIndex(shape);
if (index > 0)
{
this.setChildIndex(shape, index - 1);
}
}
The moveUp() and moveToFront() methods work similarly to the moveToBack() and
moveDown() methods.