Unlike in ActionScript2, we cannot use a MovieClip´s or Sprites´ z-Property to arrange objects on the z-axis. However, the new ActionScript3-handling provides a solution which comes in even handier..
Bring object to front
function moveUpfront( clip:DisplayObject ):void {
clip.parent.setChildIndex(clip, clip.parent.numChildren-1);
}
Send object to back
function moveToBack( clip:DisplayObject ):void {
clip.parent.setChildIndex(clip, 0);
}
Move one up
function moveForward( clip:DisplayObject ): void {
var currentDepth = clip.parent.getChildIndex(clip);
if(currentDepth<clip.parent.numChildren-1){
clip.parent.setChildIndex(clip, currentDepth+1);
}
}
Move one down
function moveBackward( clip:DisplayObject ): void {
var currentDepth = clip.parent.getChildIndex(clip);
if(currentDepth>0){
clip.parent.setChildIndex(clip, currentDepth-1);
}
}
Popularity: 31% [?]


Write a Comment