Reputation: 23
I've built a simple flash game which simply requires the user to navigate the mouse cursor around a maze from a start position to one of four ending positions based on their chosen answer from a multiple choice question.
I would like to incorporate a method of scoring into the game. This is my code so far, the scoring system doesn't work as when the user hits the wall or gets the answer wrong they are directed to another frame which presents them with a "incorrect" screen and allows them to click a button which says retry. The retry button brings them back to the main frame which ultimately resets the score to 0. How would I go about passing variables to other frames if possible?
import flash.events.Event;
import flash.net.*;
var isStart = false;
var score:Number = 0;
mc_wall.addEventListener(MouseEvent.MOUSE_OVER,overWall);
function overWall(e:Event) {
if (isStart == true){
gotoAndStop(5);
score -= -2;
}
}
mc_start.addEventListener(MouseEvent.MOUSE_OVER,overStart);
function overStart(e:Event) {
isStart = true;
}
mc_blue.addEventListener(MouseEvent.MOUSE_OVER,overBlue);
function overBlue(e:Event) {
if (isStart == true){
gotoAndStop(4);
score += 10;
isStart = false;
}
}
mc_red.addEventListener(MouseEvent.MOUSE_OVER,overRed);
function overRed(e:Event) {
if (isStart == true){
gotoAndStop(6);
score -= -2;
isStart = false;
}
}
mc_green.addEventListener(MouseEvent.MOUSE_OVER,overGreen);
function overGreen(e:Event) {
if (isStart == true){
gotoAndStop(6);
score -= -2;
isStart = false;
}
}
mc_yellow.addEventListener(MouseEvent.MOUSE_OVER,overYellow);
function overYellow(e:Event) {
if (isStart == true){
gotoAndStop(6);
score -= -2;
isStart = false;
}
}
Any help would be greatly appreciated
Upvotes: 0
Views: 983
Reputation: 461
When creating flash games, in my opinion, it is better to use external classes.
One fix would be to add a frame right before your main code and set your score variable equal to zero in that frame. That way score is only set to zero once, and when going back to your main frame it will keep the same score. (you probably want to add an if statement when subtracting score, in less you want to allow a negative score)
The better way to do it would be to use external classes and hold your main code in a Main class. This class would have a constructor and only initialize score to zero once.
-Travis
Upvotes: 1