Remove all childs with AS3

A code snippet I tend to use quite often. And one that I tend to forget how I wrote the last time i used it.

Using a while:

while (this.numChildren > 0)
{
    removeChild(this.getChildAt(0));
}

As part of an event handler:

private function eventHandler(e:Event):void
{
    e.target.parent.removeChild(e.target);
}

When using Flex:

someObject.removeAllChildren();

Latest articles