-1
我有一個4幀的場景。在第一幀有兩個按鈕,Instructions
和Start
。 Instructions
將我引導至第4幀,其中的指示是,並且Start
將我引導至第2幀,其中游戲是。遊戲結束後,我被引導到第3幀,在那裏有一個說主菜單的按鈕,它應該將我重定向到主菜單。但是,主菜單按鈕不起作用,並且會在標題中顯示Error #1009
。我提前爲任何愚蠢道歉,因爲這是我第一次使用AS3。這裏是代碼:AS3 TypeError:錯誤#1009:無法訪問空對象引用的屬性或方法。 (按鈕和gotoAndPlay)
public function projectFinal()
{
startBtn.addEventListener(MouseEvent.CLICK, startGame);
instructionBtn.addEventListener(MouseEvent.CLICK, instructions);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyboardDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyboardUp);
specialTimer.addEventListener(TimerEvent.TIMER, spawnBonus);
monsterTimer.addEventListener(TimerEvent.TIMER, moveMonsters);
mainBtn.addEventListener(MouseEvent.CLICK, endGame);
backBtn.addEventListener(MouseEvent.CLICK, goBack);
}
function startGame(event:MouseEvent):void
{
gotoAndPlay(2);
gameStarted = true;
specialTimer.start();
monsterTimer.start();
spaceShip.score = 0;
//createMonsterRow(monsterRow);
}
function instructions(event:MouseEvent):void
{
gotoAndPlay(4);
trace ("pressed ins");
}
function endGame(event:MouseEvent):void
{
gotoAndPlay(1);
trace("pressed main");
}
function goBack(event:MouseEvent):void
{
gotoAndPlay(1);
}
你好,stop();不幸的是沒有解決問題。我將mainBtn和backBtn eventListeners從公共函數中移出,並將它們置於下面粘貼的自己的函數下。 Null錯誤現在消失了,我現在沒有錯誤,但後退按鈕和主菜單按鈕仍然拒絕工作。功能GoBack的(事件:MouseEvent)方法:無效 \t \t { \t \t \t backBtn.addEventListener(MouseEvent.CLICK,GoBack的); \t \t \t gotoAndPlay(1); (「press back」); \t \t \t trace(「pressed」); \t \t} – NStu
爲了補充說明,我爲沒有工作的按鈕拋出了跟蹤語句,當我按下按鈕時,它不會輸出。我猜這是一個圖層問題,eventListeners找不到按鈕,因爲它不在第一幀。嘆。 – NStu
確保按鈕和事件偵聽器全部位於同一幀上,並查看是否跨越所有4個幀。 stop();命令阻止應用程序在幀中循環,並控制代碼使其跳回或轉發。每幀必須有一個stop()才能工作。 – Gone3d