Showing posts with label container. Show all posts
Showing posts with label container. Show all posts

Tuesday, May 3, 2011

AS3 - Children adding reverse

Today I learned an extra feature of adding children into a DisplayObject in reverse.
Normally I would make two loops. First one is adding the children, the second is placing the children in reverse.
But... it can be done so much easier:

for(var i:int = 0; i < numChildren; i++)
{

container.addChildAt(child,0);

}

The second parameter sets the child on the first place.

For many known, not for me.. maybe not for you either....

Thursday, July 23, 2009

getNextHighestDepth in as3

In as2 you were able to put a movieclip on top of all the other containing movieclips. I'm working with as3 now and was searching for this same option.

You can do it with one line of code:

as2:

//container is the parent of the movieclip
movieclip.swapDepths(container.getNextHighestDepth());

as3:

//container is the parent of the movieclip
container.setChildIndex(movieclip, (container.numChildren - 1));