当我取消注释mcMain时,我遇到了一个非常类似的问题。方法调用。当我尝试在舞台上调用一个实例时,它会显示“1061:通过带有静态类型Class的引用调用可能未定义的方法addEventListener。”
我之前在另一台计算机上做过类似的事情,我不知道为什么会这样做。我正在使用Adobe 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();
//}
}
答案 0 :(得分:1)
我从您的屏幕截图中相信您将对象mcMain命名为类名,但不是对象名称的实例。单击属性面板并为实例指定一个名称,这是您在AS3中用来引用它的名称,如果您想在AS3中创建对象的新实例,那么您将使用的另一个名称(它是有效的)班级名称)。
答案 1 :(得分:0)
检查mcMain
的定义方式。应该是var mcMain:MovieClip;
之类的东西。