我得到了一个这样的剧本来获得分数
package
{
public class ScoreHolder
{
static public var score:Number = 0;
}
}
框架代码
import ScoreHolder;
function checkButtonsone():void
{
if (fisoneclicked21 && fistwoclicked)
{
ScoreHolder.score += 10;
Score_t1.text = ScoreHolder.score.toString();
acmessage.visible = true;
acmessage.play();
gotoAndPlay(116);//LEVEL 2
}
}
现在我写了高分代码,但没有用。
Higscore代码
publice var sharedData:SharedObject;
sharedData = SharedObject.getLocal("snake_info");
if(sharedData.data.highScore == null){ //if it is being called for the first time it will be null. so change it to 0.
sharedData.data.highScore = 0;
}
{
if(score > sharedData.data.highScore){
//if score greater than highscore then set highscore = score and save it.
sharedData.data.highScore = score;
sharedData.flush();
}
//display highscore
txtHighScore.text = String(sharedData.data.highScore);
我收到1120错误。我想我把代码放错了。我无法弄清楚我该怎么做。我
答案 0 :(得分:0)
错别字。解决不存在的变量(可能)。
public var sharedData:SharedObject = SharedObject.getLocal("snake_info");
if (sharedData.data.highScore == null)
{
//if it is being called for the first time it will be null. so change it to 0.
sharedData.data.highScore = 0;
}
if (ScoreHolder.score > sharedData.data.highScore)
{
//if score greater than highscore then set highscore = score and save it.
sharedData.data.highScore = ScoreHolder.score;
sharedData.flush();
}
//display highscore
txtHighScore.text = ScoreHolder.score.toString();