0
我實際上試圖檢查一個遊戲的得分是否是一個高分。然後如果是這樣,則分數將被添加到排行榜。 但是我得到這個錯誤:類型錯誤#1009在閃光cs6使用AS3
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FlashGame_fla::MainTimeline/checkBananaHS()
在我的遊戲,在那個特定的幀,這是將鏈接到checkBananaHS()的代碼:
function rpslsWon():void
{
gameOverBananaMC.visible = true;
bananaWinLose.visible = true;
bananaWinLose.text = "Kampai " + cPlayerData.pName + "! You are totally bananas!! \nYour Score: " + pBananaScore;
toMenuBtn.visible = true;
rollAgainBtn.visible = true;
toMenuBtn.addEventListener(MouseEvent.CLICK, Click_backtoMain);
rollAgainBtn.addEventListener(MouseEvent.CLICK, backtoBanana);
saveItBtn.addEventListener(MouseEvent.CLICK, checkBananaHS);
cPlayerData.pBananaScore = pBananaScore;
saveData();
tracePlayerData();
}
這是一段代碼在高分的框架:
var rpslsHighScore:int;
var rpslsHSName:String;
rpslsHighScore = 0;
rpslsHSName = "";
//rpslsHighScore = 0;
bananaWinnerDisplay.text = " ";
bananaScoreDisplay.text = "0";
function checkBananaHS(event:MouseEvent):void
{
if ((cPlayerData.pBananaScore > rpslsHighScore ||
rpslsHighScore == 0) && cPlayerData.pBananaScore > 0)
{
trace("There's a new high score for Banana");
rpslsHighScore = cPlayerData.pBananaScore;
rpslsHSName = cPlayerData.pName;
bananaScoreDisplay.text = "" + rpslsHighScore;
bananaWinnerDisplay.text = rpslsHSName;
saveData();
}
}
我只是無法設法解決這個錯誤。誰能幫我嗎?非常感謝!
是的,我在Flash中運行了調試工具,並且它將我引導到此行bananaScoreDisplay.text =「」+ rpslsHighScore;那是什麼意思? –
'banadaScroreDisplay'尚未設置(而是'bananaScoreDisplay = null')。如果它不爲空,它會接受該值,即使「rpslsHighScore」爲空/ NaN –
表示該對象,bananaScoreDisplay尚未創建? –