Reputation: 45
So I have trouble with the z-index, all of my objects have z-index of 0, and as new objects are created they come above the ones that need to be in front. I know about setting z index commands, but if I have 50 objects, I have to write and manually set z-index for each one, witch is kinda lame. How can I fix this? This is probably simple but Im new to AS3.
Upvotes: 1
Views: 11120
Reputation: 4870
If by z-index you mean the z
value of a DisplayObject, that doesn't affect the layering of them. Depth ordering is handled by the display list of its parent
.
You can make a DisplayObject go all the way to the back by using container.addChildAt(displayObject, 0);
or container.setChildIndex(displayObject,0);
if it's already added to that parent's display list.
You don't have to change the indexes of all other children of the same parent.
If you want something to be layered right behind another DisplayObject, first find out what the index of that child is:
var i:uint = container.getChildIndex(theOneToHideBehind);
and then set the index of your DisplayObject to that value:
container.setChildIndex(myDisplayObject, i);
Upvotes: 5