Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to Display a game score throughout the Scenes

Participant ,
Mar 12, 2015 Mar 12, 2015

Hi there Actionscript geniuses. I have stumble upon this problem. As a novice in actionscript in particular and programming in general, I am very pleased that I manage to pull this scoreboard script ( listed below), for my quiz game. The script is simple, it adds points when clicking on the right button, and subtract points when clicking on the wrong button. The problem is that while this script works great on my first scene, it doesn't work on my next scene anymore. The buttons are not working and the score board is back to zero, it's as if the script does not exists. In both scenes the buttons and the text objects are the same symbols, as well the Instance names. The script resides inside actionscript .as file. What is missing or wrong in this script or concept?

I understand the dilemmas regarding using scenes, some people love them and some hate them. I also notice that Adobe itself warns about the use of scenes, but never the less, because of the current level of my flash pro cc 14 knowledge, I incline to use them.

package {

  import flash.display.MovieClip

  import flash.events.MouseEvent;

  public class scoreMe2 extends MovieClip {

  public function scoreMe2() {

  //Scoreboard starts here:

  var score: uint;

  function init(): void {

  score = 100;

  scorecounter.text = "SCORE:" + score.toString();

  clip.buttonMode = true;

  clip.addEventListener(MouseEvent.CLICK, on_press1);

  gButton.buttonMode = true;

  gButton.addEventListener(MouseEvent.CLICK, on_press2);

  button_2.buttonMode = true;

  button_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene);

  }

  //Positive button adding points

  function on_press1(event: MouseEvent): void {

  updateScore();

  }

  function updateScore(): void {

  gotoAndStop(2);

  score += 100;

  scorecounter.text = "SCORE:" + score.toString()

  }

  function fl_ClickToGoToScene(event: MouseEvent): void {

  MovieClip(this.root).gotoAndPlay(1, "Scene 2");

  }

  //Negative button subtracting points

  function on_press2(event: MouseEvent): void {

  score += -20;

  scorecounter.text = "SCORE:" + score.toString();

  }

  init();

  //Scoreboard ends here:

  }

  }

}

TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 12, 2015 Mar 12, 2015

It's not really a matter of love or hate, it's a matter of practicality.  Scenes work well for uscripted animations that flow from one section to the next.  When you start involving coding and navigation you are heading into a troublesome realm if you choose to use scenes.  They are simply problematic when you start to try to use them with code.

Your best bet is to create separate movieclips as your scenes and place them along the timeline of the first scene.  That way you can easily have all your variables at the ready by having them in a layer that extends the length of the timeline needed.  You should be able to convert to this somewhat easily if you just copy the scene timelines into movieclips.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2015 Mar 12, 2015
LATEST

Ok I'm going to give at a try. this solution sounds to me like a work around, the scenes, something that were great in concept but was badly implemented. But let give this solution a try and see when happened. I'll let you know

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines