Actionscript 3: Remove all elements from a Movieclip

I’m always trying to empty out a clip and this is by far the best way :

while (target_mc.numChildren) {
target_mc.removeChildAt(0);
}

or if you prefer to be verbose :

var total:uint = target_mc.numChildren;
for (var i:uint = 0; i < total; i++) {
target_mc.removeChildAt(0);
}

or if you prefer single function :

for (var i:uint = 0; i < target_mc.numChildren; i++) {
target_mc.removeChildAt(0);
i--;
}

Here is a user submitted version :

while (target_mc.numChildren > 0) {
target_mc.removeChildAt(target_mc.numChildren - 1);
}

Here is a one line version :

while (target_mc.numChildren != 0) target_mc.removeChildAt(0);

Saw this one on Adobe website :

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

I think that’s it.

[ad#Google Adsense]

Flash on smart phones

According to Dilbert, flash on smart phones really isn’t a good idea.

dilbert1