Select Page

Useful AS3: Removing Child DisplayObjects

One of the most useful lines of code I have found in AS3 is the following:

while (numChildren > 0) removeChildAt(0)

This removes every child DisplayObject from the DisplayObject you run it on. Very useful for cleaning up after yourself.

Another example:

while (myMc.numChildren > 0) myMc.removeChildAt(0);