我实际上是在尝试检查游戏的分数是否为高分。如果是,则分数将添加到排行榜。 但是我收到了这个错误:
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();
}
}
我无法设法修复错误。谁能帮我吗?非常感谢!
答案 0 :(得分:0)
checkBananaHS()
中的一个变量在调用时未设置。因此,当您尝试访问该对象的属性时,它会因为没有任何内容而出错。
请记住,这意味着您的函数中尚未设置以下对象之一:
cPlayerData
bananaScoreDisplay
bananaWinnerDisplay
在每个函数上运行一个跟踪,一个函数开头一次,看看哪一个没有返回[Object object]