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

五迷三道 提交于 2019-12-11 08:17:22

问题


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)


回答1:


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


来源:https://stackoverflow.com/questions/41642545/i-get-a-nan-error-on-score-counter-to-when-player-has-choose-level-from-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!