To an extent this is working, but it’s only removing the tempBullet object if its y position starts at < 200, not if it reaches that point after being spawned somewhere further down the stage:
if(firing && bulletTimeOut == 0)
{
var tempBullet = new Bullet();
bullets.push(tempBullet);
tempBullet.x = x;
tempBullet.y = y-10;
stage.addChild(tempBullet);
trace(bullets.length);
if(tempBullet.y < 200)
{
bullets.splice(tempBullet, 1);
stage.removeChild(tempBullet);
}
bulletTimeOut = 5;
}
Is this code happening in a loop?
I think that rather than just checking the position of
tempBulletyou intended to loop through the whole bullets array to remove any bullets that have gone past 200px.