共享对象保存和加载问题 [英] Shared object save and load issue

查看:93
本文介绍了共享对象保存和加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的脚本来得分

I got a script like this for score

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
}
}

现在我写了高分代码,但是没有用.

Now I write high score code but did not work.

Higscore的代码

Code for 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错误.我认为我把代码放到错误的一侧.我不知道该怎么办.我

I get a 1120 error.I think I put the code to wrong side.I can't figure out what should I do.I

推荐答案

错别字.解决不存在的变量(可能).

Typos. Addressing non-existent variables (probably).

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();

这篇关于共享对象保存和加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆