# hitTestObject to not always existing object

**URL:** <https://forum.kirupa.com/t/hittestobject-to-not-always-existing-object/271347>\
**Category:** Uncategorized\
**Created:** [September 22, 2008, 3:04am UTC](https://forum.kirupa.com/t/hittestobject-to-not-always-existing-object/271347 "2008-09-22T03:04:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![HMPoweredMan](https://avatars.discourse-cdn.com/v4/letter/h/57b2e6/32.png) [@HMPoweredMan](https://forum.kirupa.com/u/HMPoweredMan)\
**Post date:** [September 22, 2008, 3:04am UTC](https://forum.kirupa.com/t/hittestobject-to-not-always-existing-object/271347/1 "2008-09-22T03:04:10Z")

</div>

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

```auto

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:

```auto

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:

```auto

        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.
