I have a for loop in my enemy class that checks when enemy bullets are on stage, so that it can move them and check hit detection and things like that. Here is the code for the loop:
for (var i:int = 0; i < Stats.enemyBulletArray.length; i++) //This runs as long as enemy bullets exist on the stage {
q = new Point(0, Stats.enemyBulletArray*.y); //I just use this to find the bullet's actual y value.
if (Stats.enemyBulletArray*.name == "Normal Bullet") //
{
Stats.enemyBulletArray*.y += bulletSpeed * Stats.gameSpeed;
}
if (localToGlobal(q).y > 660)
{
removeChild(Stats.enemyBulletArray*);
Stats.enemyBulletArray.splice(i, 1);
}
}
The code runs great as long as the bullet array length is greater than 0. However, there are certain points when there aren’t any bullets on the stage, and the moment the array length drops to 0, I get this error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/removeChild()
at Enemies::NormalShootEnemy/loop()
The bullet is still removed though, and if I dismiss the error, the game runs fine. (The array doesn’t seem be affected either). Obviously it’s not a huge deal then, but what I’m wondering is how can I stop this error from popping up in the first place?