I m currently building the damage mechanic for my game. Two classes handle this, the hurt class, and the collision class. The hurt class passes an instance of itself to the hurtCollision method of the collision class, so that the collision class can detect a collision between the player and that instance of hurt (which is a display object). When I try to access that function however, I get this error:
1061: Call to a possibly undefined method hurtCollision through a reference with static type Class.
Here are the two classes:
The collision class (you can just ctrl f to hurtCollision):
package
{
import flash.display.MovieClip;
public class Collision extends MovieClip
{
private var e:*;
static public var _playerX:*;
static public var _playerY:*;
private var HIT_BOTTOM_1X:Number;
private var HIT_BOTTOM_2X:Number;
private var HIT_BOTTOM_3X:Number;
private var HIT_TOP_1X:Number;
private var HIT_TOP_2X:Number;
private var HIT_TOP_3X:Number;
private var HIT_R_1X:Number;
private var HIT_R_2X:Number;
private var HIT_R_3X:Number;
private var HIT_L_1X:Number;
private var HIT_L_2X:Number;
private var HIT_L_3X:Number;
private var HIT_BOTTOM_1Y:Number;
private var HIT_BOTTOM_2Y:Number;
private var HIT_BOTTOM_3Y:Number;
private var HIT_TOP_1Y:Number;
private var HIT_TOP_2Y:Number;
private var HIT_TOP_3Y:Number;
private var HIT_R_1Y:Number;
private var HIT_R_2Y:Number;
private var HIT_R_3Y:Number;
private var HIT_L_1Y:Number;
private var HIT_L_2Y:Number;
private var HIT_L_3Y:Number;
public function Collision(enginePass:*)
{
e = enginePass;
}
public function detectCollisions(object:*):void
{
_playerX = e._player.x;
_playerY = e._player.y;
HIT_BOTTOM_1X = object.x - object.width/2;
HIT_BOTTOM_2X = object.x;
HIT_BOTTOM_3X = object.x + object.width/2;
HIT_TOP_1X = object.x - object.width/2;
HIT_TOP_2X = object.x;
HIT_TOP_3X = object.x + object.width/2;
HIT_R_1X = object.x + object.width/2;
HIT_R_2X = object.x + object.width/2;
HIT_R_3X = object.x + object.width/2;
HIT_L_1X = object.x - object.width/2;
HIT_L_2X = object.x - object.width/2;
HIT_L_3X = object.x - object.width/2;
HIT_BOTTOM_1Y = object.y + object.height/2;
HIT_BOTTOM_2Y = object.y + object.height/2;
HIT_BOTTOM_3Y = object.y + object.height/2;
HIT_TOP_1Y = object.y - object.height/2;
HIT_TOP_2Y = object.y - object.height/2;
HIT_TOP_3Y = object.y - object.height/2;
HIT_R_1Y = object.y + object.height/2 - object.height/4;
HIT_R_2Y = object.y;
HIT_R_3Y = object.y - object.height/2 + object.height/4;
HIT_L_1Y = object.y + object.height/2 - object.height/4;
HIT_L_2Y = object.y;
HIT_L_3Y = object.y - object.height/2 - object.height/4;
if(e._ground.hitTestPoint(HIT_BOTTOM_1X,HIT_BOTTOM_1Y,true) || e._ground.hitTestPoint(HIT_BOTTOM_2X,HIT_BOTTOM_2Y,true)
|| e._ground.hitTestPoint(HIT_BOTTOM_3X,HIT_BOTTOM_3Y,true))
{
e._touchGround = true;
if(e._vy < 0)
{
e._vy = 0;
}
}
if(e._ground.hitTestPoint(HIT_TOP_1X,HIT_TOP_1Y,true) || e._ground.hitTestPoint(HIT_TOP_2X,HIT_TOP_2Y,true)
|| e._ground.hitTestPoint(HIT_TOP_3X,HIT_TOP_3Y,true))
{
e._jump = false;
e._vy = -(e._vy) - 5;
}
if(e._ground.hitTestPoint(HIT_R_1X,HIT_R_1Y,true) || e._ground.hitTestPoint(HIT_R_2X,HIT_R_2Y,true)
|| e._ground.hitTestPoint(HIT_R_3X,HIT_R_3Y,true))
{
if(e._vx > 0)
{
e._vy += e._vx;
}
if(e._ground.hitTestPoint(HIT_TOP_3X, HIT_TOP_3Y, true))
{
if(e._vx > 0)
{
e._vx = -(e._vx) *2;
}
}
}
if(e._ground.hitTestPoint(HIT_L_1X,HIT_L_1Y,true) || e._ground.hitTestPoint(HIT_L_2X,HIT_L_2Y,true)
|| e._ground.hitTestPoint(HIT_L_3X,HIT_L_3Y,true))
{
if(e._vx < 0)
{
e._vy += Math.abs(e._vx);
}
if(e._ground.hitTestPoint(HIT_TOP_1X, HIT_TOP_1Y, true))
{
if(e._vx < 0)
{
e._vx = -(e._vx) *2;
}
}
}
if(e._ground.hitTestPoint(HIT_TOP_3X, HIT_TOP_3Y, true) && e._ground.hitTestPoint(HIT_BOTTOM_3X, HIT_BOTTOM_3Y, true))
{
e._vy += 20;
}
if(e._ground.hitTestPoint(HIT_TOP_1X, HIT_TOP_1Y, true) && e._ground.hitTestPoint(HIT_BOTTOM_1X, HIT_BOTTOM_1Y, true))
{
e._vy += 20;
}
if(e._ground.hitTestPoint(e._player.x,e._player.y, true))
{
e._vy = -(e._vy);
e._vx = -(e._vx);
}
else
{
if(!(e._ground.hitTestPoint(HIT_BOTTOM_1X,HIT_BOTTOM_1Y,true) || e._ground.hitTestPoint(HIT_BOTTOM_2X,HIT_BOTTOM_2Y,true)
|| e._ground.hitTestPoint(HIT_BOTTOM_3X,HIT_BOTTOM_3Y,true)))
{
e._vy -= 1;
e._touchGround = false;
}
}
}
public function hurtCollision(hurtObject:*)
{
if(hurtObject.hitTestPoint(HIT_BOTTOM_1X,HIT_BOTTOM_1Y,true) || hurtObject.hitTestPoint(HIT_BOTTOM_2X,HIT_BOTTOM_2Y,true)
|| hurtObject.hitTestPoint(HIT_BOTTOM_3X,HIT_BOTTOM_3Y,true))
{
e.hurtPlayer();
}
if(hurtObject.hitTestPoint(HIT_TOP_1X,HIT_TOP_1Y,true) || hurtObject.hitTestPoint(HIT_TOP_2X,HIT_TOP_2Y,true)
|| hurtObject.hitTestPoint(HIT_TOP_3X,HIT_TOP_3Y,true))
{
e.hurtPlayer();
}
if(hurtObject.hitTestPoint(HIT_R_1X,HIT_R_1Y,true) || hurtObject.hitTestPoint(HIT_R_2X,HIT_R_2Y,true)
|| hurtObject.hitTestPoint(HIT_R_3X,HIT_R_3Y,true))
{
e.hurtPlayer();
}
if(hurtObject.hitTestPoint(HIT_L_1X,HIT_L_1Y,true) || hurtObject.hitTestPoint(HIT_L_2X,HIT_L_2Y,true)
|| hurtObject.hitTestPoint(HIT_L_3X,HIT_L_3Y,true))
{
e.hurtPlayer();
}
}
}
}
The hurt class:
package
{ import flash.display.MovieClip; import flash.events.Event; import Collision;
public class Hurt extends MovieClip
{
public function Hurt()
{
addEventListener(Event.ENTER_FRAME, enterFrame);
}
private function enterFrame(e:Event)
{
Collision.hurtCollision(this);
}
}
}
EDIT: Just to let you all know, e.hurtPlayer is just the document class method that controls the player s health.