So i have a list of enemies instantiated in a array and i have them on screen. When they get shot, i want the enemy that has been shot to be removed from the screen. BTW the enemy Class has AS Linkage with the Enemy movieClip, same thing with the Bullet. I understand the problem is that it cant compare and remove but i dont know how to fix it. Basically i would love to know how can i remove instances of a class file that are stored in a array?
This is what i got so far:
stage.addEventListener(MouseEvent.CLICK, shoot);
var enemyList:Array = new Array();
addEnemies(608.75, 371.85);
function addEnemies(xLoc:Number, yLoc:Number):void {
var enemy:Enemy = new Enemy(xLoc, yLoc);
addChild(enemy);
enemyList.push(enemy);
}
function shoot(event:MouseEvent):void{
for(var i:int = 0; i < 4; i++){
var enemy:Enemy = enemyList[i];
if(scope.redDot.hitTestObject(enemy)){
trace("SHOT TO DEATH");
}
else{
trace("DIDNT DIE");
}
}
}
I Keep getting this error in the output window: TypeError: Error #1010: A term is undefined and has no properties. at sniper_fla::MainTimeline/shoot()[sniper_fla.MainTimeline::frame1:58]
Any help would be appreciated!