Useful AS3: Removing Child DisplayObjects

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

  1.  
  2. while (numChildren > 0) removeChildAt(0)
  3.  

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

Another example:

  1.  
  2. while (myMc.numChildren > 0) myMc.removeChildAt(0);
  3.  

Leave a Reply