PDA

View Full Version : [AS3] Removing multiple objects of an array from the stage.


RockHopper Games
04-03-2011, 02:55 AM
I have multiple objects on screen that are all part of an array. I want them all to be removed after a hitTest. Everything's working ok except that only one object is being removed.
for(var i:int = 0; i < enemyList.length; i++){
if (enemyList[i].hitTestObject(man)) {
var enemy = enemyList.indexOf(i)
man.removeEventListener(Event.ENTER_FRAME, checkHitTest);
this.removeChild(enemyList.splice(i, 1)[0]);
}
}
I played around with it a bit, but ultimately, I need some help. Does anyone know what I'm doing wrong here? The this.removeChild is the problem, but I'm just not sure why it's not working.

audiohominis
04-03-2011, 09:10 AM
I'm seeing some unnecessary acrobatics in that code.
for each(var i:* in enemyList)
{
this.removeChild(i);
};

RockHopper Games
04-03-2011, 06:33 PM
for each(var i:* in enemyList)
{
this.removeChild(i);
};

I tried swapping that in, but it wasn't working right. From what I understand, something like this:

this.removeChild(enemyList.splice(i, enemyList.length)[0]);

should work, but it's still just removing one element from the array.:confused: