Posted By

noelchan on 08/31/10


delete children

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Delete Children in MovieClip

 / Published in: ActionScript 3

  1. private function deleteChildrenInMovieClip(_movieClip:Sprite):void {
  2. if (_movieClip.numChildren>0) {
  3. for (var i:uint = 0; i < _movieClip.numChildren; i++) {
  4. _movieClip.removeChildAt(i);
  5. }
  6. }
  7. }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: xerode on September 1, 2010

I've not tested this code but I'm pretty sure it won't work in its current state. When you remove a child then the childIndex of all the siblings are reordered. So what was previously at childIndex 2 will become 1 and so on.

The correct way to do this is to change _movieClip.removeChildAt(i); to _movieClip.removeChildAt(0); - you will still walk through the children and remove all of them but without throwing any errors.

Posted By: adamhas on September 1, 2010

^what he said

Posted By: binhdocco on September 29, 2010

xerode said true, other we can use

while(_movieClip.numChildren>0) { _movieClip.removeChildAt(0); }

Posted By: Empreintes on October 11, 2010

=> work fine

You need to login to post a comment.