vendredi 20 janvier 2017

Shared object save and load issue

I write script like this

package
{
public class ScoreHolder
{
    static public var score:Number = 0;
}
}

Frame code

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.

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

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

Aucun commentaire:

Enregistrer un commentaire