1

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)

KucuKeko
  • 111
  • 8

1 Answers1

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
    }
}
Organis
  • 7,243
  • 2
  • 12
  • 14
  • brilliant :) Thank you...I wanna ask about timer.Can I do same thing on timer. – KucuKeko Jan 14 '17 at 16:51
  • Yes, you can have a timer as a static class variable. Yet if you want more functionality shared over this one timeline I would advise you to create a class for this MovieClip (or main timeline) and access its fields via "this" statement. – Organis Jan 14 '17 at 21:16
  • Hi organis..I add the high score over that but it's not work can you check out please. http://stackoverflow.com/questions/41761659/shared-object-save-and-load-issue – KucuKeko Jan 20 '17 at 10:47