The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: I need some help with a simple multiple choice quiz

  1. #1

    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 second key frame;
    Code:
    score.text = myscore+"/30"; // updating the score 
    
    
    if(myscore>=20){smiley.visible=true}
    else
    {smiley.visible=false}

  2. #2

    Resolved

    I got it to work I also wrote it so you can give different points for different answers:

    Code:
    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() }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012