header ads

Making MCQ In Action Script 3.0 | ActionScript 3.0 2021

Hey everyone! Here’s a super brief tutorial. The Multiple Choice Question has been Made For Kids Education. Let's Learn Step By Step How to Make it.


Open Animate and create a new File 1280 x 720 and save the file name "Quiz" (ActionScript 3).


Now it's time to design your quiz interface. make a start button and set their instance name star_btn.

Create a rounded rectangle 1149 x 125 and set their instance name ques_mc. Add a Dynamic TextField with the Text Tool and name it "txt".

Create four rounded rectangle 382 x 108 and set their instance name Op1, Op2, Op3, Op4. Add a Dynamic TextField with the Text Tool and name it "Op_txt"

  • Add a Dynamic TextField with the Text Tool and name it "score_txt".
  • Add a Dynamic TextField with the Text Tool and name it "wrong_txt".
  • Add a Button with the Text "Replay" and name it "Replay_btn".
  • On the first frame Create a new layer and name it "Actions" and press F9.
  • Adding Click Event To Start the Quiz
  • 
    stop();
    
    start_btn.addEventListener(MouseEvent.CLICK,  PlayGame);
    
    function PlayGame (MouseEvent)
    
    {
    	
    	gotoAndStop(2);
    }
    
  • On the second frame press F9 and adding questions
  • 
      //These are the classes we'll need to import for our class to work;   
    
    //import the Tween class
    import fl.transitions.Tween;
    //import the transitions
    import fl.transitions.easing.*;
    import flash.filters.*;       
            
            
    stop();
    
    var tween1:Tween;
    var tween2:Tween;
    var tween3:Tween;
    var tween4:Tween;
    var tween5:Tween;
    var Qnum = 0;
    var score = 0;
    var miss = 0;
    
    
    
    
    var Questions:Object = [
    						
    	{
    		Ques: "The Binary Coded Decimal (BCD) uses",
    		Options: ["6 bits","8 bits","16 bits","32 bits"],
    		Ans:	"6 bits"
    	},
    						
    						
    	{
    		Ques: "Which of the following is billionth of a second?",
    		Options: ["Microsecond","Nanosecond","Terabyte","Gigabyte"],
    		Ans:	"Nanosecond"
    							
    	},
    						
    						
    	{
    		Ques: "The two kinds of main memory are",
    		Options: ["CDs and DVDs","RAM and ROM","Primary and secondary","Direct and sequential"],
    		Ans:	"RAM and ROM"
    	},
    	
    						
    	]
                
                
    
          
      //Second Frame Code
          
      //Add Variable for options
      
      var no1 = 0;							
    						
    function GameStart()
    
    {
    
    	//Adding Tween in Questoins
    	tween1 = new Tween(ques_mc, 'alpha', Regular.easeInOut, 0, 2, 4, true);
    
    	tween1 = new Tween(ques_mc, 'y', Bounce.easeOut, -200.65, 200.85, 3, true);
    	
    	
    	
    	//Adding Tween in Options
    	tween2 = new Tween(Op1, 'y', Bounce.easeOut, -100, Op1.y, 3, true);
    	tween3 = new Tween(Op2, 'y', Bounce.easeOut, -100, Op2.y, 3, true);
    	tween4 = new Tween(Op3, 'y', Bounce.easeOut, -100, Op3.y, 3, true);
    	tween5 = new Tween(Op4, 'y', Bounce.easeOut, -100, Op4.y, 3, true);
    
    
    
    	
    	
    	//Adding text fomr array object in Question And Options;
    	
    	ques_mc.txt.text = Questions[Qnum].Ques;
    	
    	Op1.Op_txt.text = Questions[Qnum].Options[no1];
    	no1++
    	Op2.Op_txt.text = Questions[Qnum].Options[no1];
    	no1++;
    	Op3.Op_txt.text = Questions[Qnum].Options[no1];
    	no1++;
    	Op4.Op_txt.text = Questions[Qnum].Options[no1];
    
    	//reset no1 value
    	no1 = 0;
    }				
    						
    	
        // Calling The Function 
        
    	GameStart();	
          
         
          
  • Now Ctrl+Enter and test the movie (swf) question and option fetch done
  • 
          
          for (var i = 1; i <= 4; i++)
    	{
    		
    		this["Op" + i].buttonMode = true;
    		
    		this["Op" + i].addEventListener(MouseEvent.CLICK, ClickFunction1);
    	}
        
        
        
        function ClickFunction1 (e:MouseEvent):void
    {
    
    
    	//Store buttons name in variable
        
    	var btn = e.currentTarget.name;
    	
    	
    //if user click Option-1
        
    	if(btn == "Op1")
    	{
    		//Cheking if current target is true.
            
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play(); // We will make this movie clip in the next step.
            
            
    	}
        
        
    	else
    	{
    		trace("Try Again");
    		try_mc.play(); // We will make this movie clip in the next step.
    	}
        
    		
    	}
    	
        
        
        
        //if user click Option-2
        
    	else if(btn == "Op2")
    	{
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play();
    	}	
    	else
    	{
    		trace("Try Again");
    		try_mc.play();
    	}
    		
    	}
    	
    	
        //if user click Option-3
        
    	else if(btn == "Op3")
    	{
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play();
    	}	
    	else
    	{
    		trace("Try Again");
    		try_mc.play();
    	}
    		
    	}
        
        
        //if user click Option-4
        
        else if(btn == "Op4")
    	{
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play();
    	}	
    	else
    	{
    		trace("Try Again");
    		try_mc.play();
    	}
    		
    	}
    	
    
    	
    	
    }
        
        
    
          
        
  • Create a new layer and name it "good_and_try"


  • Make a Good Work Object as you want to design. when the user clicked on the right option. it will appear.

  • goto (goood work movie clip) and put stop(); command on first frame as you see in video. On the last frame add gotoAndStop(1); and call parent function Object(parent).NextFunction();
  •  
             
     // put on first frame of Good Work Mc
        Stop();
             
             
     // put on last frame of Good Work Mc
        gotoAndStop(1);
    
    	Object(parent).NextFunction();
             
     

  • Do same in try again mc but on the last frame change Object(parent).NextFunction(); to Object(parent).WrongAnwer();


  • You can also add sound of good work and try again in movieclips as you can see i add sound both moiveclips
  • Create a good work function
  •  
         
         function NextFunction()
    {
    	score++;
    	Qnum++;
        
        
    	//check  display question = total question;
        
    	if(Qnum >= Questions.length)
    	{
    	
    		// if All Questions Completed. go to and stop on the third frame.
            
    		gotoAndStop(3);
    	}
        
    	else
    	{
        
        	//Calling Again Game Start Funciton
            
    		GameStart();
    		
    		
    	}
    	
    	
    }
        
  • Create a try again function
  •  
         
         function WrongAnwer()
    {
    
    	// simple when user click on wrong answer
        
    	miss++;
    
    }
    
    
        
  • Create a restart game funciton and showing result

  •  
      
      
    // Frame Third Code  
      
    stop();
    
    
    Replay_btn.addEventListener(MouseEvent.CLICK, replay_funC);
    
    function replay_funC(e:MouseEvent){
    	
    	
    	gotoAndStop(1);
    	
    }
    
    
    
        
  • Adding Score and Missed
  •  
    // Frame Third Code  
    
    //Showing score and miss on display
    
    
    score_txt.text     =  String(score);
    wrong_txt.text     =  String(miss);
    
    
    
        

  • Our quiz app is now complete.
  • Here is the code in full:
  •  
      
      
    // Frame One Code  
      
    stop();
    
    start_btn.addEventListener(MouseEvent.CLICK,  PlayGame);
    
    function PlayGame (MouseEvent)
    
    {
    	
    	gotoAndStop(2);
    }
    
    
        
     
    // Frame Second Code  
    
    //import the Tween class
    import fl.transitions.Tween;
    //import the transitions
    import fl.transitions.easing.*;
    import flash.filters.*;
    
    stop();
    
    
    var tween1:Tween;
    var tween2:Tween;
    var tween3:Tween;
    var tween4:Tween;
    var tween5:Tween;
    var Qnum = 0;
    var score = 0;
    var miss = 0;
    
    
    
    var Questions:Object = [
    						
    {
    		Ques: "The Binary Coded Decimal (BCD) uses",
    		Options: ["6 bits","8 bits","16 bits","32 bits"],
    		Ans:	"6 bits"
    },
    						
    						
    {
    		Ques: "Which of the following is billionth of a second?",
    		Options: ["Microsecond","Nanosecond","Terabyte","Gigabyte"],
    		Ans:	"Nanosecond"
    						
    },
    						
    						
    {
    		Ques: "The two kinds of main memory are",
    		Options: ["CDs and DVDs","RAM and ROM","Primary and secondary","Direct and sequential"],
    		Ans:	"RAM and ROM"
    },
    						
    			]
    				
    						
    
    var no1 = 0;							
    						
    function GameStart()
    
    {
    
    	//Adding Tween in Questoins
    	tween1 = new Tween(ques_mc, 'alpha', Regular.easeInOut, 0, 2, 4, true);
    
    	tween1 = new Tween(ques_mc, 'y', Bounce.easeOut, -200.65, 200.85, 3, true);
    	
    	
    	
    	//Adding Tween in Options
    	tween2 = new Tween(Op1, 'y', Bounce.easeOut, -100, Op1.y, 3, true);
    	tween3 = new Tween(Op2, 'y', Bounce.easeOut, -100, Op2.y, 3, true);
    	tween4 = new Tween(Op3, 'y', Bounce.easeOut, -100, Op3.y, 3, true);
    	tween5 = new Tween(Op4, 'y', Bounce.easeOut, -100, Op4.y, 3, true);
    
    
    	
    	
    	//Adding text fomr array object in Question And Options;
    	
    	ques_mc.txt.text = Questions[Qnum].Ques;
    	
    	Op1.Op_txt.text = Questions[Qnum].Options[no1];
    	no1++
    	Op2.Op_txt.text = Questions[Qnum].Options[no1];
    	no1++;
    	Op3.Op_txt.text = Questions[Qnum].Options[no1];
    	no1++;
    	Op4.Op_txt.text = Questions[Qnum].Options[no1];
    
    
    	no1 = 0;
    }				
    						
    						
    	GameStart();					
    											
    
          for (var i = 1; i <= 4; i++)
    	{
    		
    		this["Op" + i].buttonMode = true;
    		
    		this["Op" + i].addEventListener(MouseEvent.CLICK, ClickFunction1);
    	}
        
        
        
        function ClickFunction1 (e:MouseEvent):void
    {
    
    
    	//Store buttons name in variable
        
    	var btn = e.currentTarget.name;
    	
    	
    	//if user click Option-1
        
    	if(btn == "Op1")
    	{
    		//Cheking if current target is true.
            
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play(); // We will make this movie clip in the next step.
            
            
    	}
        
        
    	else
    	{
    		trace("Try Again");
    		try_mc.play(); // We will make this movie clip in the next step.
    	}
        
    		
    	}
    	
        
        
        
        //if user click Option-2
        
    	else if(btn == "Op2")
    	{
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play();
    	}	
    	else
    	{
    		trace("Try Again");
    		try_mc.play();
    	}
    		
    	}
    	
    	
        //if user click Option-3
        
    	else if(btn == "Op3")
    	{
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play();
    	}	
    	else
    	{
    		trace("Try Again");
    		try_mc.play();
    	}
    		
    	}
        
        
        //if user click Option-4
        
        else if(btn == "Op4")
    	{
    		if (e.currentTarget.Op_txt.text == Questions[Qnum].Ans)
    		{
    		trace("Good Work");
    		good_mc.play();
    	}	
    	else
    	{
    		trace("Try Again");
    		try_mc.play();
    	}
    		
    	}
    	
    	
    
    	
    	
    }
    
    
    
    
    
     function NextFunction()
    {
    	score++;
    	Qnum++;
    	
    	if(Qnum >= Questions.length)
    	{
    	
    		
    		gotoAndStop(3);
    	}
        
    	else
    	{
    		GameStart();
    		
    		
    	}
    	
    	
    }
        
        
    
    function WrongAnwer()
    {
    	miss++;
    
    }
    
    
    
    						
    						
    						
    
    
        
     
     
    // Frame Third Code  
    
    
    
    
    stop();
    
    
    Replay_btn.addEventListener(MouseEvent.CLICK, replay_funC);
    
    function replay_funC(e:MouseEvent){
    	
    	
    	gotoAndStop(1);
    	
    }
    
    score_txt.text     =  String(score);
    wrong_txt.text     =  String(miss);
    
    
    
    
    
        
    .........Thank You.........


    Post a Comment

    0 Comments