How to Display a game score throughout the Scenes
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:
}
}
}
