-
[RESOLVED] I need some help with a simple multiple choice quiz
I have used files from a tutorial on this site to create a very basic quiz that keeps a score.
It works very well but I want to get it so that when the user selects and answer (a,b,c,d) it processes it rather than having a separate button to submit each answer. So that the user makes their choices from the 3 questions then clicks one button to see their score. I appreciate any help I can get, has been a couple years since I had to do any AS3 coding.
There are 2 key frames in the file;
AS3 code on first key frame;
Code:
stop();
// using the import directive to import the required classes
import fl.controls.RadioButtonGroup;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
// starting out with a score of 0
var myscore = 0; score.text = myscore+"";
// creating a new instance of the radioButtonGroup Class
var mygroup1:RadioButtonGroup = new RadioButtonGroup("group1");
a1.group = a2.group = a3.group = a4.group = mygroup1;
b1.addEventListener(MouseEvent.CLICK, quizHandler1)
function quizHandler1(event:MouseEvent):void{
if(mygroup1.selection.label=="a"){myscore+=10; smiley.visible=true;}
else{ nextFrame(); smiley.visible=false;}
}
var mygroup2:RadioButtonGroup = new RadioButtonGroup("group2");
an1.group = an2.group = an3.group = an4.group = mygroup2;
score.text = myscore+""; // showing updated score
b2.addEventListener(MouseEvent.CLICK, quizHandler2)
function quizHandler2(event:MouseEvent):void{
if(mygroup2.selection.label=="b"){ myscore+=10; smiley.visible=true}
else{ nextFrame(); smiley.visible=false}
}
var mygroup3:RadioButtonGroup = new RadioButtonGroup("group3");
ans1.group = ans2.group = ans3.group = ans4.group = mygroup3;
score.text = myscore+"";
b3.addEventListener(MouseEvent.CLICK, quizHandler3);
function quizHandler3(event:MouseEvent):void{
if(mygroup3.selection.label=="a"){ myscore+=10; nextFrame()}
else{nextFrame() }
}
AS3 code on first key frame;
Code:
score.text = myscore+"/30"; // updating the score
if(myscore>=20){smiley.visible=true}
else
{smiley.visible=false}
-
figured it out, also coded it so different answers deliver different scores;
stop();
// using the import directive to import the required classes
import fl.controls.RadioButtonGroup;
import flash.events.MouseEvent;
// starting out with a score of 0
var myscore = 0; score.text = myscore+"";
// creating a new instance of the radioButtonGroup Class
var mygroup1:RadioButtonGroup = new RadioButtonGroup("group1");
a1.group = a2.group = a3.group = a4.group = a5.group = mygroup1;
var mygroup2:RadioButtonGroup = new RadioButtonGroup("group2");
an1.group = an2.group = an3.group = an4.group = mygroup2;
score.text = myscore+""; // showing updated score
var mygroup3:RadioButtonGroup = new RadioButtonGroup("group3");
ans1.group = ans2.group = ans3.group = ans4.group = mygroup3;
score.text = myscore+"";
b3.addEventListener(MouseEvent.CLICK, quizHandler1)
function quizHandler1(event:MouseEvent):void{
if(mygroup1.selection.label=="a"){myscore+=10; smiley.visible=true;}
else if(mygroup1.selection.label=="b"){myscore+=5; smiley.visible=true;}
else if(mygroup1.selection.label=="c"){myscore+=1; smiley.visible=true;}
else{nextFrame(); smiley.visible=false;}
}
b3.addEventListener(MouseEvent.CLICK, quizHandler2)
function quizHandler2(event:MouseEvent):void{
if(mygroup2.selection.label=="a"){ myscore+=10; smiley.visible=true}
else if(mygroup2.selection.label=="b"){myscore+=5; smiley.visible=true;}
else if(mygroup2.selection.label=="c"){myscore+=1; smiley.visible=true;}
else{ nextFrame(); smiley.visible=false}
}
b3.addEventListener(MouseEvent.CLICK, quizHandler3);
function quizHandler3(event:MouseEvent):void{
if(mygroup3.selection.label=="a"){ myscore+=10; nextFrame()}
else if(mygroup3.selection.label=="b"){myscore+=5; nextFrame()}
else if(mygroup3.selection.label=="c"){myscore+=1; nextFrame()}
else{nextFrame() }
}
-
.
Hi,
You add an event listener to the radioGroup,
You might need the appropriate imports too
PHP Code:
import fl.controls.RadioButton; import fl.controls.RadioButtonGroup; import flash.events.Event;
and the event listener
PHP Code:
var mygroup1:RadioButtonGroup = new RadioButtonGroup("group1"); a1.group = a2.group = a3.group = a4.group = mygroup1; mygroup1.addEventListener(Event.CHANGE, quizHandler1);
function quizHandler1(event:Event):void { if (mygroup1.selection.label == "a") { myscore += 10; smiley.visible = true; } else { nextFrame(); smiley.visible = false; } }
thats as much as I can do without the fla and seeing the setup and stuff.
you should get used to using code like so
var myscore:Number = 0;
score.text = String(myscore) + "";
instead of
var myscore = 0;
score.text = myscore+"";
Last edited by fruitbeard; 09-27-2014 at 09:40 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|