(As2) swapDepths Vs (As3) setChildIndex
AS2 was an anarchy language, if you need to put a movieClip visually above all the things in the stage, you can do movieClip.swapDepths(this.getNextHighestDepth()). So it works, but in reality your are swapping your movieClip with a movieClip that didn’t exist, so in AS3 you can’t do that but we have setChildIndex method. You Can do setChildIndex(numChildren-1)
AS2

AS3

March 28th, 2008 at 5:24 pm
Thanks
May 23rd, 2008 at 6:04 am
So basically, in your example, when swapping the child object at index 0 to index 3, the other children are “pushed” down the stacking order? This IS better than having a movie clip (originally at index 3) killed.
May 23rd, 2008 at 7:06 am
Yep that’s what happens, it is better but it also forces you to delete that displayObject manually, as in AS2 you’d just ‘replace’ it
June 23rd, 2008 at 6:49 pm
This seems to be a common approach, but I’m skeptical. What happens in the following scenario? Let’s assume container is an empty DisplayObjectContainer…
———————————–
var s1:Sprite = new Sprite();
var s2:Sprite = new Sprite();
container.addChild(s1);
container.addChildAt(s2, 42);
container.setChildIndex(s1, container.numChildren - 1);
———————————–
Now, what are the indeces of s1 and s2?
June 24th, 2008 at 9:52 am
Well it will throw you an error as there’s no index 42.
if you want you can immediatly change the index of s1 by container.addChildAt(s2,0); which would make s1 top to s2.
August 27th, 2008 at 8:00 am
[...] #2 not possible anymore… if you want a detailed explanation visit dreaming in Flash blog, and read more about swapDepths() in AS3 (it’s explained with a [...]