Hello there.
Im not sure if i remove my enemys from array correctly, because all works great untill some point when one enemy though its dead (and not on stage), it remains in my array (checked it with trace(enemyArray).
Heres all my code about array:
Main Timeline:
var enemy1Array:Array=new Array();
var max1:int=10;
var i1:int;
var Enemy1MC:MovieClip;
addEventListener(Event.ENTER_FRAME, enemy1array);
function enemy1array(event:Event):void
{
for(i1=0; i1<max1; i1++)
{
Enemy1MC=new Enemy11();
}
}
var enemy0Timer:Timer;
enemy0Timer=new Timer(11000,8);
enemy0Timer.addEventListener(TimerEvent.TIMER, enemy1spawn0);
enemy0Timer.start();
function enemy1spawn0(event:TimerEvent):void
{
Enemy1MC.x=323;
Enemy1MC.y=234;
addChildAt(Enemy1MC, 5);
enemy1Array.push(Enemy1MC); // here i push enemys into the array
Enemy1MC.scaleX=25/100;
Enemy1MC.scaleY=25/100;
Enemy1MC.gotoAndPlay(1);
}
// here comes some other timers (constructed the same) where enemy1MC spawns bla bla
addEventListener(Event.ENTER_FRAME, Enemy1Damage)
function Enemy1Damage(event:Event):void
{
trace(enemy1Array);
for(i1=0; i1<enemy1Array.length; i1++)
{
if(enemy1Array[i1].currentFrame==53)
{
heroHP-=Enemy1DMG;
}
else if(!enemy1Array[i1].currentFrame==53)
{
heroHP-=0;
}
}
}
And then in my Enemy11.as class file:
if(Enemy1HP<0)
{
Enemy1HP=0;
this.gotoAndPlay(61);
}
//from 61 to 72 is the death animation
if(this.currentFrame==72)
{
_root.enemy1Array.splice(this, 1);
parent.removeChild(this);
}
Im not sure if i remove them correctly or if other part of code is wrong, cos they get removed correctly (when im shooting the enemys, they die and then they get removed), but then after 30-40 seconds one gets stuck in the array, though he’s no longer on the stage(i also noticed my heroHP drops at that point, though the enemy is no longer there)