1061:通过具有静态类型Class的引用调用可能未定义的方法hitTestPoint

时间:2012-11-11 01:03:40

标签: actionscript-3 flash

我试图在我的游戏中进行碰撞检测并且教程使用的是hitTestPoint,如果有人可以提供帮助,这里是代码的一部分。 Ground只是一个块状的电影剪辑,玩家就是玩家:

stage.addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void
{
    if (ground.hitTestPoint(borat.x + leftBumpPoint.x,borat.y + leftBumpPoint.y,true))
    {
        trace("leftBumping");
        leftBumping = true;
    }
    else
    {
        leftBumping = false;
    }

    if (ground.hitTestPoint(borat.x + rightBumpPoint.x,borat.y + rightBumpPoint.y,true))
    {
        trace("rightBumping");
        rightBumping = true;
    }
    else
    {
        rightBumping = false;
    }

    if (ground.hitTestPoint(borat.x + upBumpPoint.x,borat.y + upBumpPoint.y,true))
    {
        trace("upBumping");
        upBumping = true;
    }
    else
    {
        upBumping = false;
    }

    if (ground.hitTestPoint(borat.x + downBumpPoint.x,borat.y + downBumpPoint.y,true))
    {
        trace("downBumping");
        downBumping = true;
    }
    else
    {
        downBumping = false;
    }

}

我一直在收到这些错误:

Scene 1, Layer 'actions', Frame 1, Line 37  1061: Call to a possibly undefined method hitTestPoint through a reference with static type Class.

Scene 1, Layer 'actions', Frame 1, Line 47  1061: Call to a possibly undefined method hitTestPoint through a reference with static type Class.

Scene 1, Layer 'actions', Frame 1, Line 57  1061: Call to a possibly undefined method hitTestPoint through a reference with static type Class.

Scene 1, Layer 'actions', Frame 1, Line 67  1061: Call to a possibly undefined method hitTestPoint through a reference with static type Class.

感谢任何花时间阅读此内容的人!

1 个答案:

答案 0 :(得分:0)

地面的类型是什么?它必须是MovieClip的一个实例,才能使用它,你不能在类上调用该方法。

//this will work
var ground:MovieClip = new SomeAsset();
ground.hitTestPoint();

//this won't
SomeAsset.hitTestPoint();