1

当我取消注释 mcMain 时,我遇到了一个非常相似的问题。方法调用。当我尝试在舞台上调用实例时,它显示“1061:通过静态类型 Class 的引用调用可能未定义的方法 addEventListener。”

我之前在另一台计算机上做过类似的事情,我不确定为什么会这样。我正在使用 Adob​​e Flash CS5.5 和 AS3.0。

//These variables will note which keys are down
//We don't need the up or down key just yet
//but we will later
var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
//the main character's speed
var mainSpeed:Number = 7;

//adding a listener to mcMain which will make it move
//based on the key strokes that are down
mcMain.addEventListener(Event.ENTER_FRAME, moveChar);
function moveChar(event:Event):void
{
    //if certain keys are down then move the character
    if (leftKeyDown)
    {
        trace("left");
        //mcMain.x -= mainSpeed;
    }
    if (rightKeyDown)
    {
        trace("right");
        //mcMain.x += mainSpeed;
    }
    //if(upKeyDown || mainJumping){
    ////mainJump();
    //}
}

http://i.stack.imgur.com/PtR7F.png

4

2 回答 2

1

我相信从您的屏幕截图中,您将对象 mcMain 命名为类名,而不是对象名称的实例。单击属性面板并为实例命名,这是您在 AS3 中用来引用它的名称,如果您想在 AS3 中创建对象的新实例,您将使用另一个名称(它实际上是类名)。

于 2012-06-11T18:37:05.193 回答
0

检查如何mcMain定义。应该是类似的东西var mcMain:MovieClip;

于 2012-06-11T18:01:02.507 回答