Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Box for test... 1

Status
Not open for further replies.

brutteforcce

Technical User
Jun 23, 2006
105
RO
I want to make a test with check boxes... I made a model, but I don't know how to demark a marked one when I chose another one...
The code is this :
on (release) {gotoAndStop(20);
_root.a=_root.a+1;
}

This is the code when it marks it...

on (release) {gotoAndStop(1);
_root.a=_root.a-1;

}

This is the code when it demarks it...

This code is fot the check boxes with the correct answer, and the checks boxes that aren't correct don't do nothing... So, the variable a is the number of the correct answers...

Pleases help me and if you have a better idea for calculating the correct answers please tell it to...

 
Thanks, but I have 2 problems...
I tryed the code with 2 questions...
1. If I answer both correct ( it's tell me that I chosen the correct answer ), the score isn't two... it's one.
2. If my answer is for example the second when I press next in the next question the second mark is selected as default or if I answered with 3 at the first the third is selected, etc... All the check boxes should be unselected.
Thank you very much for youre help and I please you to tell me how can I put more questions in a frame, when you will have time... you helped me enought today...
PS: You're the best!!! Thanks!!!
 
Sorry again... the score is working, I just writed:

correctAnswer = 1; // or 2, or 3
stop();

instead of:

var correctAnswer:Number = 1; // or 2, or 3
stop();

My mistake again, but I steel have the other problem...
Let's say I have 4 questions. At the first one I chose answer 3, I click next and at the second one answer 3 is marked, if I change the mark to the first answer at the third question the first answer is marked.
By default when you pass to another question with the next button, all the check boxes must be unchecked...

Please think how can I put more questions, five for example in a single frame...

Thanks!!!
 
OK, let's tackle the issues one by one.

I added the function to clear the checkboxes in the frame 1. You just call that function in each subsequent frames.

The script in the frame 1:

[tt]//
var checkboxCount:Number = 3;
var checkedID:Number = 0;
for (var i = 1; i<=checkboxCount; i++) {
var checkbox:MovieClip = this["check"+i];
checkbox.ID = i;
checkbox.onPress = function():Void {
if (this.ID == checkedID) {
checkedID = 0;
this.gotoAndStop("uncheck");
} else {
checkedID = this.ID;
clearCheckboxes();
this.gotoAndStop("check");
}
trace("checkedID: "+checkedID);
};
}
//
var score:Number = 0;
var correctAnswer:Number = 1; // or whatever
//
stop();
//
function clearCheckboxes():Void {
for (var i = 1; i<=checkboxCount; i++) {
this["check"+i].gotoAndStop("uncheck");
}
}
//
btnNext.onPress = function():Void {
if (checkedID != correctAnswer) {
trace("Wrong answer: score "+score);
} else {
score++;
trace("Correct answer: score "+score);
}
gotoAndStop(_currentframe+1);
};

//[/tt]

The script in the frame 2 onwards:

[tt]//
clearCheckboxes();
correctAnswer = 2; // or whatever
stop();

//[/tt]

Kenneth Kawamoto
 
Thank you very much again, this issue is rezolved thanks to you :D...
And now, my last problem: more than one question in a frame.(it doesn't metter if the questions are in different layers... if it has something to do with this)...
Thanks again, I wouldn't manage without you...
 
Please try to help me because I want to build the site...
Thanks...
 
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
 
Thank you very very much!!! You're the best!!!
Thanks to you my site will be brought to life...
Can I do anything for you?

Thank you again, you made me very happy! I hope you will have all you desire in life...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top