Answered
where and how to declare global variables
I am creating a multiple choice quiz in Flash. I have created
one movie clip named mc_Quiz. This movie clip contains an action
layer and an object layer. Thw action layer contains 1 keyframe
with code ( code for a button that moves to the next frame).
The object layer contains 11 keyframes 10 of the keyframes contains
a single movie clip question, (mc_Q1 through mc_Q10) and a btnNext to move to the next frame. The question movie clips (e.g. mc_Q1) contains a “btnCheck” button and the code to check the answer.
The 11th frame contains a movie click that contains a “userName” input text box, a user “score” dynamic text box, and a “submit” button. I am not submitting the information anywhere yet, but have it so that when I click the ‘submit” button it enters “Please enter your name” if it is empty. And if is not empty it enters “Thank you.”
What I need to do is to have the “btnCheck” to add 10 points for every correct answer to a variable. Then place that total in the “score” dynamictext box when the user moves from the 10th frame to the 11th. I am not sure where to declare the variable and how to add to the variable each time the correct answer is given.
How is this done?
Here is one thing that does not work.
First frame of “mc_Quiz”:
stop()
var advanceNext:Number = currentFrame;
var static; userScore:Number;
btnNext.addEventListener(MouseEvent.CLICK, nextQuestion);
function nextQuestion(evt:MouseEvent):void{
gotoAndStop(advanceNext ++);
}
In frame on of “mc_Q1”
stop()
messageBox.text = ""; // Clears the Response box
var correctAnswer:String = "sanctify"; // Sets correct answer for comparison
var userAnswer:String; // with value from radio button group.
var rbg:Object = rbA.group; // Get the name of the ragio button group from the first button.
btnCheck1.addEventListener(MouseEvent.CLICK, checkAnswer1);
function checkAnswer1(evt:MouseEvent):void {
userAnswer = String(rbg.selectedData);
if (userAnswer == correctAnswer) {
messageBox.text = "Yes, " + userAnswer + " is CORRECT!";
userScore = score.value + 10;
rbA.enabled = false;
rbB.enabled = false;
rbC.enabled = false;
rbD.enabled = false;
}
else {
messageBox.text = "Your answer is INCORRECT.";
rbA.enabled = false;
rbB.enabled = false;
rbC.enabled = false;
rbD.enabled = false;
}
}
I actually have no real clue where to declare the variable or how to add 10 points to it when I select the correct answer. It appears to me that I must some how change this variable within the function of the button.
The object layer contains 11 keyframes 10 of the keyframes contains
a single movie clip question, (mc_Q1 through mc_Q10) and a btnNext to move to the next frame. The question movie clips (e.g. mc_Q1) contains a “btnCheck” button and the code to check the answer.
The 11th frame contains a movie click that contains a “userName” input text box, a user “score” dynamic text box, and a “submit” button. I am not submitting the information anywhere yet, but have it so that when I click the ‘submit” button it enters “Please enter your name” if it is empty. And if is not empty it enters “Thank you.”
What I need to do is to have the “btnCheck” to add 10 points for every correct answer to a variable. Then place that total in the “score” dynamictext box when the user moves from the 10th frame to the 11th. I am not sure where to declare the variable and how to add to the variable each time the correct answer is given.
How is this done?
Here is one thing that does not work.
First frame of “mc_Quiz”:
stop()
var advanceNext:Number = currentFrame;
var static; userScore:Number;
btnNext.addEventListener(MouseEvent.CLICK, nextQuestion);
function nextQuestion(evt:MouseEvent):void{
gotoAndStop(advanceNext ++);
}
In frame on of “mc_Q1”
stop()
messageBox.text = ""; // Clears the Response box
var correctAnswer:String = "sanctify"; // Sets correct answer for comparison
var userAnswer:String; // with value from radio button group.
var rbg:Object = rbA.group; // Get the name of the ragio button group from the first button.
btnCheck1.addEventListener(MouseEvent.CLICK, checkAnswer1);
function checkAnswer1(evt:MouseEvent):void {
userAnswer = String(rbg.selectedData);
if (userAnswer == correctAnswer) {
messageBox.text = "Yes, " + userAnswer + " is CORRECT!";
userScore = score.value + 10;
rbA.enabled = false;
rbB.enabled = false;
rbC.enabled = false;
rbD.enabled = false;
}
else {
messageBox.text = "Your answer is INCORRECT.";
rbA.enabled = false;
rbB.enabled = false;
rbC.enabled = false;
rbD.enabled = false;
}
}
I actually have no real clue where to declare the variable or how to add 10 points to it when I select the correct answer. It appears to me that I must some how change this variable within the function of the button.