I’ve been trying to make a movieClip be able to fire a “bullet,” but so far I haven’t had any luck with removing it. I’ve removed all the unnecessary code:
function shoot(e:MouseEvent){
var bullet:shootyThing = new shootyThing()
addChild(bullet)
bullet.addEventListener(Event.ENTER_FRAME, moveBullet)
}
function moveBullet(e:Event){
trace("something")
e.currentTarget.range = e.currentTarget.range - Math.abs(Math.cos(e.currentTarget.myAtan2) * e.currentTarget.velocity);
e.currentTarget.range = e.currentTarget.range - Math.abs(Math.sin(e.currentTarget.myAtan2) * e.currentTarget.velocity);
if(e.currentTarget.range <= 0 && e.currentTarget.removed == false){
e.currentTarget.removed = true
removeChild(e.currentTarget.bullet)
}
}
In short, when the bullet’s range hits zero, I’m thrown the error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/removeChild()
at Trigonometry_fla::MainTimeline/moveBullet()
I’ve never been able to figure out how adding and removing children works, so if anyone has a solution or a good tutorial it’s welcome. Thanks in advance.
EDIT: Jeez, I just noticed that I never actually said the problem came with removing the bullet. I know removeChild is what’s failing, but I don’t know how to fix it.