I have been busy - OK, busy watching the World Cup on TV: let's sort it out before the next match starts!
This movie has now 3 frames. Frame 1 has 5 questions, and each question has 3 checkbox MovieClips. Checkbox MCs are now named "check1-1", "check1-2", "check1-3" (question 1), ... "check5-1", "check5-2", "check5-3" (question 5). Hope you get the idea for this naming convention.
There's also a button called "btnNext" as before.
The script for the frame 1:
[tt]// AS2 main timeline
var score:Number = 0;
var correctAnswerArray:Array = [1, 2, 3, 1, 2];
var questionCount:Number = 5;
var checkboxCount:Number = 3;
var checkedIDArray:Array = [0, 0, 0, 0, 0];
for (var i = 0; i<=questionCount; i++) {
for (var j = 1; j<=checkboxCount; j++) {
var checkbox:MovieClip = this["check"+i+"-"+j];
checkbox.ID = i+"-"+j;
checkbox.onPress = function():Void {
var group:Number = parseInt(this.ID.split("-")[0]);
var checkBoxID:Number = parseInt(this.ID.split("-")[1]);
if (checkBoxID == checkedIDArray[group-1]) {
checkedIDArray[group-1] = 0;
this.gotoAndStop("uncheck");
} else {
checkedIDArray[group-1] = checkBoxID;
clearCheckboxes(group);
this.gotoAndStop("check");
}
trace("checkedIDArray: "+checkedIDArray);
};
}
}
//
stop();
//
function clearCheckboxes(group:Number):Void {
for (var i = 1; i<=checkboxCount; i++) {
this["check"+group+"-"+i].gotoAndStop("uncheck");
}
}
function clearAllCheckboxes():Void {
for (var i = 1; i<=questionCount; i++) {
clearCheckboxes(i);
}
checkedIDArray = [0, 0, 0, 0, 0];
}
//
btnNext.onPress = function():Void {
for (var i = 0; i<questionCount; i++) {
if (checkedIDArray
== correctAnswerArray) {
score++;
}
}
trace("Current score: "+score);
gotoAndStop(_currentframe+1);
};
//[/tt]
var correctAnswerArray:Array = [1, 2, 3, 1, 2];
This is where you set the correct answer for the questions on this page. This example is setting the correct answers as follows: Q1 = 1, Q2 = 2, Q3 = 3, Q4 = 1, Q5 = 2.
The second frame has exactly the same as frame 1 on Stage, but this time questions are from question 6 to question 10. However do not change the name of the checkboxes. "check1-1" is now the first checkbox for the question 6.
The script for the frame 2:
[tt]//AS2 main timeline
clearAllCheckboxes();
correctAnswerArray = [2, 3, 1, 2, 3];
stop();
//[/tt]
This time I set the correct answers as follows: Q6 = 2, Q7 = 3, Q8 = 1, Q9 = 2, Q10 = 3.
The third frame is the final score page, no checkboxes or buttons on Stage.
The script for frame 3:
[tt]//
trace("The total score is "+score);
stop();
//[/tt]
That's it. You can add any number of questions by duplicating the frame 2.
Kenneth Kawamoto