How to remove a child in an array in ActionScript 3.0?
Here's my code. I put the child I want to remove in an array called nailList[] and put it on gameStage.
function makeNails():void
{
for (var i=0; i< 3; i++)
{
for (var j=0; j<3; j++)
{
var tempNail = new Nail2(j * C.NAIL_DISTANCE + C.NAIL_START_X,
i * C.NAIL_DISTANCE + C.NAIL_START_Y);
nailList.push(tempNail);
gameStage.addChild(tempNail);
}
}
gameStage.addEventListener(Event.ENTER_FRAME,update);
gameStage.addEventListener(MouseEvent.CLICK, clickToHit);
}
Here's the code I used to remove the nails. But nothing happens after this code. The nails are still there.
for (var j:int = nailList.length; j >= 0; j--)
{
removeNails(j);
trace("Remove Nail");
}
function removeNails(idx:int)
{
gameStage.removeChild(nailList[idx]);
nailList.splice(idx,0);
}
I want to remove the MovieClip so that I can restart the game and add new ones.