I'm following this tutorial for Action Script 3 on http://markbennison.com/actionscript/as3-space-shooter/2-coding-projectiles/
I'm on part 2 Coding projectiles I don't know why its saying Error all the time when I press play
"ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller."
Here's the exact code im trying to work through to shoot bullets when spacebar is pressed, there are more but idk how to fix the Argument Error.
function addBullet(startX, startY): void {
//declare an object instance from the bullet Class
var b: Bullet = new Bullet();
//set the new bullet's x-y coordinates
b.x = startX;
b.y = startY;
//add the new bullet to the stage
stage.addChild(b);
//store the object in an array
bullets_arr.push(b);
}
function moveBullet(): void {
//loop through all instances of the bullet
//loop from '0' to 'number_of_bullets'
for (var i: int = 0; i < bullets_arr.length; i++) {
//move the bullet
bullets_arr[i].x += bulletSpeed;
//if the bullet flies off the screen, remove it
if (bullets_arr[i].x > stage.stageWidth) {
//remove the bullet from the stage
stage.removeChild(bullets_arr[i]);
//remove the bullet from the array
bullets_arr.removeAt(i);
}
}
}
Can someone give me tips to change anything or?