Arrange (z) the order of objects in Flash using ActionScript 3?

Is it possible to arrange (z) the order of objects in Flash using ActionScript 3?

eg. I have 3 instances of the characters on the given layer, and I want to fulfill the equivalent of “Bring to the front”, “Bring forward” and / or aim a specific position z.

+7
flash actionscript-3 z-index flash-cs5
source share
2 answers

You can change the z-index (storage order) of a movie clip at the same level using a script action like this.

parent.setChildIndex(childObject, i) 

Change childObject to the name of the clip you want to change z-index, I change to an integer (the desired value of the z-index).

If you want this to happen in a mouse event, enter the code above inside the function and attach an event listener to the button to call this function in the mouse event.

+9
source share

Leading the front will be something like:

myObject.parent.setChildIndex( myObject, myObject.parent.numChildren - 1);

Forward will be something like:

myObject.parent.setChildIndex( myObject, myObject.parent.getChildIndex( myObject ) + 1);

Setting a specific z index will be:

myObject.parent.setChildIndex( myObject, newZIndex);

+5
source share

All Articles