So, im using this code to remove a couple of movie clips from my stage:
for (var i:uint = 0; i < this.numChildren; i++)
{
if (this.getChildAt(i) is MovieClip
&& pecasInGame.indexOf(this.getChildAt(i)) >= 0)
{
removeChild(this.getChildAt(i));
}
}
But its not really working well… I have 5 movie clips to remove and they are all added dinamically, when these movieclips are added i insert then into this array “pecasInGame”, and when there is five of then I try to remove using the aforementioned loop.
The problem is, it only removes 3 of then, the 0, 2 and 4 objects.. The 1 and 3 arent even listed in the loop. Any idea why would that happen??
You’re removing the display objects, so the indexes are changing WHILE your loop goes on.
Change it this way:
Other option: use your array to remove the objects, like this