OK I have a robot class and a shot class. I’m having a problem because the shot object doesn’t always exist, so I think it is causing this error. I don’t know how to get around it.
I want the robot class to check every frame if the shot class is hitting it. This is causing a problem.
Error I get
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at robotHitbox/eFrame()
The reason why I think it is because the object doesn’t always exist is because I use the same method to see if the robot hits the player, and that works correctly and the player always exists.
The shot is instantiated here:
function mainShoot():void{
var pl_shot:shot = new shot()
if (gamePaused == false) {
if (mainShots < 3){
mainFiring = true
}
if (mainFiring == true && mainFirable == true){
mainShots ++
this.addChild(pl_shot);
trace(pl_shot.parent)
mainFiring = false
mainFirable = false
snd_shoot.play();
shotTimer.reset()
shotTimer.start()
}
}
}
OK heres the code for the robot class:
private function eFrame(event:Event):void{
if(this.hitTestObject(pl_hitbox)){
resetLvl()
}
if(this.hitTestObject(pl_shot)){
resetLvl()
}
}
it works for the pl_hitbox but not the pl_shot.