UPDATE: From flash player 11 up, you use the new mySprite.removeChildren(); method (Thanks OMA!) for targeting older versions, the code below is still relevant...
you may be tempted to use a for loop to recursively remove movieclips or sprites nested in another display object.
but this single line will take care of it for you:
while (mySprite.numChildren) mySprite.removeChildAt(0);
8 comments:
Thanx for this ! Saved my day!
info AT multimediaal DOT nl
Yeah!!!
Saved me a ton of time and frustration. Thanks.
Thank YOU!
This is not recursive, its iterative.
A recursive function should remove the children of children, and their children (if they exist).
Thanks for the clarification Muhammad! But I guess I want to make the post easily findable by google and people would probably be searching "recursive"... Also, the children of the children are deleted with this example and picked up by the garbage collection, just not recursive.
Recent versions of Flash and Adobe AIR now include a native method called removeChildren() which is faster and really recursive:
mySprite.removeChildren();
Post a Comment