當我取消註釋mcMain時,會出現非常類似的問題。方法調用。當我嘗試調用舞臺上的實例時,它會顯示「1061:通過靜態類型Class的引用調用可能未定義的方法addEventListener」。AS3調用可能未定義的方法
我在另一臺電腦上做過類似的事情,但我不確定爲什麼這樣做。我正在使用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();
//}
}
http://i.stack.imgur.com/PtR7F.png
只是一個人擡頭,因爲我以前有過這種情況。有一個罕見的錯誤可能會導致這種類型的事情。如果你的代碼沒有任何問題,請檢查我是如何修復我的:http://stackoverflow.com/q/9507999/472647 – CodeMouse92