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...

 
Here's the sample script.

The set up:
- Create a MovieClip with two key frames: one is called "uncheck", the other "check". Put stop() in the frame 1.
- Place the MovieClip on Stage in the frame 1, as many as your quiz requires.
- Name the MovieClips as "check1", "check2", "check3", etc...

The script:
[tt]// AS2 Main Timeline Frame 1
var checkboxCount:Number = 5;
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;
for (var j = 1; j<=checkboxCount; j++) {
this._parent["check"+j].gotoAndStop("uncheck");
}
this.gotoAndStop("check");
}
trace("checkedID: "+checkedID);
};
}
stop();
//[/tt]

Adjust "checkboxCount" accordingly - if you have 100 checkboxes set the checkboxCount to 100, for example.

Kenneth Kawamoto
 
Thanks, but it isn't working... If I click the check boxes nothing happens. I don't know where in that code it's an on release event or something that makes the check box to be checked and unchecked...
What should I do?
Please help!
 
Sorry!!! I found my mistake... I duplicated the movieclip and I gaved the names check1 check2 check3, etc... to the duplicated movie clips instead of the instance...
Thank you very much!!!
 
That check boxes are good for the wrong answers of the test. If you mark a correct answer a variable called "s" for example should be increased with 1 and if you demark the correct answer the variable should decrease with 1.
So, "s" will be the number of correct answers. Depending of it, the result will be given.
Please help me again...
 
Does your quiz have only one question or many questions? If it has many, it should have some sort of "go to the next question" button, and that is where you evaluate if the checked answer is correct.

Make sense?

Kenneth Kawamoto
 
Yes, I understand... I want to make a site with tests that have a different number of questions... At the moment I want the questions to be on the same page or a number of questions on a page, but I will think at your variant.
I think I will make a button "next page", and a page has 10 questions for example... I didn't think at all the details, but for now I want to know how should I find the number of correct answered questions... I tryed to put a condition something like this:
if (checkedID==4) {s=s+1};
}
IF the correct answered will be checkedID 4, so if there are 20 questions and all of them have 3 answers, for the good answer will be a condition.
It's just an idea that isn't working, so please tell me what should I do...
 
I added some extra bits to demonstrate the basic concept. A button called "btnNext" is added to the Stage.

[tt]// AS2 main timeline
var checkboxCount:Number = 5;
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;
for (var j = 1; j<=checkboxCount; j++) {
this._parent["check"+j].gotoAndStop("uncheck");
}
this.gotoAndStop("check");
}
trace("checkedID: "+checkedID);
};
}
//
var score:Number = 0;
var correctAnswer:Number = 3;

stop();
//
btnNext.onPress = function():Void {
if (checkedID != correctAnswer) {
trace("Wrong answer: score "+score);
} else {
score++;
trace("Correct answer: score "+score);
}
};

//[/tt]

(In the real app you have to set "correctAnswer" per each questions.)

Kenneth Kawamoto
 
Nice. but I want, for example a test with 20 questions that has 5 questions. Down at the page should be the next page button, and on the last page should be the Submit button, that gives a message, depending the score.
It is another problem: if somebody marks the correct answer, he will get a point, but after he can chose another answer and the point must be taken...
Thanks for the support...
 
> It is another problem: if somebody marks the correct answer, he will get a point, but after he can chose another answer and the point must be taken...

This would be done like this:

[tt]//
...
if (checkedID != correctAnswer) {
score--;
trace("Wrong answer: score "+score);
} else {
score++;
trace("Correct answer: score "+score);
}
...
//[/tt]

Note that the score can get to minus, like "-20".

Do you want all your questions in one single frame (i.e. dynamically generated questions) or spread 20 questions in 20 frames?

Kenneth Kawamoto
 
I want 5 questions in a frame, and the next five questions will be in another frame... It will switch to the next frame with 5 questions with a button called "next page", that is at the bottom of the page...
I supose I must make a layer for each question, or how can I do these?
 
What can I make so the score isn't negative... IT must be from 0 to "the number of questions".
It musn't decrease the score with a point if it answers wrong, it haves to decrease the score with a point if the correct answer was marked and then demarked...
Somebody chose de good answer, he gets a point, but then he can chose another answer at the same questions and the point must be tooken...
Try to help me with this one to please...
 
> Somebody chose de good answer, he gets a point, but then he can chose another answer at the same questions and the point must be tooken...

This does not make sense.

No matter how many times you select/deselect right/wrong answers, you only get 1 point for the right answer and 0 point for wrong answer per question. Therefore you should evaluate the selection only when "next" button is pressed.

Kenneth Kawamoto
 
Yes... You get one point for the correct answers, but if somebody selects a correct answer he gets a point... Right?
But after he selects the answer and he gets the point he can change his answer into a wrong answer and the point must be tooken because the final answer isn't correct...
Did you understand...?
 
Let's say I have a test with 20 questions and each questions has 3 choises. After the test is done he must click the submit button to see how many points he did.
If he answers correct at all the questions he must get 20 points, but if it choses the correct answer, then another answers at a question, the point that he get when he chosed the correct answer remains. So he could chose all the good answers and then he could modify them into bad answers and the score will be 20, even if all the final answers are wrong.
He could chose the good answer, then a bad answer and then the good answer again and he would take another point, so the score of the test could be 40.
That's why I need a way to give points just for the final answers...
I hope you understand me, so you could help me...
Thanks...
 
What I am saying is it's pointless to add/subtract point to/from the score until he decides on the final answer, because he can only get either 1 point or 0 point per question.

> He could chose the good answer, then a bad answer and then the good answer again and he would take another point, so the score of the test could be 40.

No, it will be 20 if you just check the final answer. No matter how many times he changes his mind he can only choose one final answer, which is either right (1 point) or wrong (0 point).

Kenneth Kawamoto
 
Sorry, I'm so stupid :D... It makes the verification of all the questions just after you press the button not any time you make a modification, if I get it right.
I hope this is the last questions...
How can I pass to the next question? I have to give it all that action again? If I'm right, where should I add the next question?
 
Now I have the correct code but I don't know to use it...
I want to have more than one question in a frame and I don't know where should I put the code for the second question and so forth...
Please help me again...
 
You need 21 frames - one question per frame plus final score frame. (It can be done in just one frame but that's for another day.)

The first frame is as it is, but the script now needs to be like this:

[tt]// AS2 main timeline
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;
for (var j = 1; j<=checkboxCount; j++) {
this._parent["check"+j].gotoAndStop("uncheck");
}
this.gotoAndStop("check");
}
trace("checkedID: "+checkedID);
};
}
//
var score:Number = 0;
var correctAnswer:Number = 1; // or 2, or 3
stop();
//
btnNext.onPress = function():Void {
if (checkedID != correctAnswer) {
trace("Wrong answer: score "+score);
} else {
score++;
trace("Correct answer: score "+score);
}
gotoAndStop(_currentframe+1);
};

//[/tt]

The second frame is the same as the first frame, but the script will be:

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

And so on until the frame 20 (question 20) - just set the "correctAnswer" to 1, 2, or 3 for each frame (question).

The frame 21 is the result page and will have no check boxes or buttons. The script will be:

[tt]//
trace("The total score is "+score); // or do something
stop();
//[/tt]

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top