Skip to main content
Inspiring
September 11, 2011
Question

Line 41 1061: Call to a possibly undefined method hitTestObject through a reference with static type

  • September 11, 2011
  • 1 reply
  • 3143 views

Im trying to use the hit test built into flash, but its failing. I have used this many time before! but this time flash is crying at me.

I Think i know why but im not sure how to fix it.

Here is my hit test code:

stage.addEventListener( Event.ENTER_FRAME, handleCollision);          

private function handleCollision( e:Event ):void           {                if (MissleMc.hitTestObject(Enemy))                {                     trace("HIT");                }                else                {                     trace("MISS");                }           }

I have tried multiple things,  Changing instances, location of the code. I currently have 4 classes, Main, Missile, Enemy and House. House has nothing it in really. Missile make a missile, Enemy Makes a enemy. And main deals with adding it all to the stage, and making it randomly appear ect.

This topic has been closed for replies.

1 reply

Inspiring
September 11, 2011

Looks like MissleMc is a class - not an instance. DisplayObject as a Class doesn't have static hitTestObject method.

Inspiring
September 11, 2011

Yes you are correct, MissleMc is a class, thats the name its exported to. But i have tryed various things.

Well i completely cahnged it now. Cleaned up my code a little created a new Bullet class, that i am currently using.

Here is the function that fire's the bullet

private function fireBullet():void

{

var newBullet:Bullet = new Bullet;

stage.addChild(newBullet);

newBullet.x = house.x;

newBullet.y = house.y;

aBulletArray.push(newBullet);

trace(aBulletArray.length);

}

So im making the instance bullet, yet still when i use the hit test it does not wotk.

Inspiring
September 11, 2011

Show fixed code related to hit test.