using ActionScript 3 on Animate, I'm trying to delete a bunch of items from the stage using Array
and for
loop. I actually downloaded this code from this site, but it doesn't seem to work for me. It will only delete one item and won't delete the others. and when I redraw the stage it will then not delete anything at all. I have another function button down the road that will restart (redraw) the game, I'm using the gotoAndPlay()
to redraw. FYI, the "squares" are sprites and the "myTFs" are text fields that are 'paired' together to become buttons. What am I doing wrong?
function mainFunc(): void {
var btnsArray: Array = new Array("square", "myTF3", "square2", "myTF2", "square4", "myTF4");
for (var ii = 0; ii < btnsArray.length; ii++) {
removeChildAt(btnsArray[ii]);
btnsArray.length = 0;
}
}
If you have an Array of DisplayObject's names you want to batch operate (e.g. remove from display list or something else) you can do the following: