当我取消注释 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();
//}
}