Swap this!

ActionScript 3 is a lovely step up from AS2 but relearning all your favorite techniques is a bit of a pain. Take for example swapDepths(). What a great little method. Sure it was working the crappy depth system of Flash 8 but it was easy. Let do this in AS3 then. Well for starts its not there because the depths are no longer there. Instead we need to change the index of a displayObject in its displayObjectContainer. Do do this you have to use the new setChildIndex() method of the displayObjectContainer. And to get the item to the top of the list you just set the index to the numChildren-1. Example:
displayObjectContainer.setChildIndex(displayObject, displayObjectContainer.numChildren-1);

One Response to “Swap this!”

  1. Pablo Says:

    After coming back to this posts so many times because I never bothered to remember it. I found out something new.

    You can actually do this in place of swapDepths:

    displayObjectContainer.swapChildren(displayObjectContainer.child1, displayObjectContainer.child2);