Search code examples
actionscript-3flashflash-cs6flash-cc

I get a "Nan" error on score counter to when player has choose level from menu


I made a score counter and if has player start level 1 and if has win,counter is keep working to next level.( Level = frame ) it's not exist any issue so far.

But when player has choice to level from menu and start level 2,counter is not work.Level 2 start from to frame 116.I get a "NaN" error.

I write a code like this scrore frame 1

var Scorecounter:Number = 0;

And Score_t1 it's a dynamic text.Use counter code on frame one

function checkButtonsone():void
{
    if(fisoneclicked21 && fistwoclicked)
    {

    Scorecounter = Scorecounter + 10;
    Score_t1.text = (Scorecounter).toString();

    acmessage.visible = true;
    acmessage.play();

    gotoAndPlay(116);//LEVEL 2
}
}

and on level 2

function checkButtonponelev2():void
{
    if(fish1clickedleveltwo && fishtwoclickedleveltwo && 
    fishthreeclickedleveltwo)

    {           
    Scorecounter = Scorecounter + 10;
    Score_t1.text = (Scorecounter).toString();

    famessage.visible = true;
    famessage.play();
}
}

I'm not using keyframe beetwen two levels.So score frame continue until last frame.(285)


Solution

  • Well, I've no idea why timeline scripting not working for you (you might want to trace Scorecounter if it inits though), but I can suggest a "global" variable solution. Create a class file ScoreHolder.as and put it in the same folder as your *.fla

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

    Then import it in any frame where you want to access the score value:

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