Okay, so I'm back after a six month hiatus. I haven't coded anything in a few weeks, so I'm a little rusty. Anyways, I'm working on a shooter again (just a small project - I expect to be done by the weekend), but I ran into a bit of a wall again with the shooting. This time I'm trying to use an array to hold all my bullets, but when I try to remove these bullets, I get an error message.
Here is my function which creates and shoots the bullet. For simplicity's sake, I set the boundary to 250 so I could check whether the bullets actually disappear or not.
private function shoot():void
{
var bullet:playerBullet = new playerBullet;
bullet.x = playerShip.x-20;
bullet.y = playerShip.y+40;
container.addChild(bullet);
bulletArray.push(bullet);
bulletCounter = 12;
shootSound.play();
addEventListener(Event.ENTER_FRAME, moveBullet);
function moveBullet(e:Event):void
{
bullet.x += playerBulletSpeed;
if (bulletArray[0].x > 250)
{
container.removeChild(bulletArray[0]);
}
}
}
In case you weren't sure, bulletCounter is what I use to keep the player from shooting.
So, when the first bullet approaches 250x, Flash gives me this error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-8()
Here's a link to the game if you think it will help. You'll notice the first bullet disappears but the rest pass through the boundary.
http://www.newgrounds.com/dump/item/d31 ... 9cc4605b0b