Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var score:int = 0;
  2.  
  3. //stroring questions
  4.  
  5. nextButton.addEventListener(MouseEvent.CLICK, DeclareXMLVariables);
  6. function DeclareXMLVariables(event:MouseEvent):void{
  7.    
  8.     nextButton.visible = false;
  9.     var tempScore:int = 0;
  10.    
  11.     //Storing answered questions
  12.     var answeredQuestion1:String = 'First Question';
  13.     var answeredQuestion2:String = 'Second Question';
  14.    
  15.     //All questions
  16.     var question1:String = test.questions.questionAnswers1.question;
  17.     var question2:String = test.questions.questionAnswers2.question;
  18.     var question3:String = test.questions.questionAnswers3.question;
  19.     var question4:String = test.questions.questionAnswers4.question;
  20.     var question5:String = test.questions.questionAnswers5.question;
  21.     var question6:String = test.questions.questionAnswers6.question;
  22.     var questions:Array = [question1, question2, question3, question4,
  23.                            question5, question6]; //storing all questions from XML file
  24.    
  25.     //Answers for question 1
  26.     var quest1Answer1:String = test.questions.questionAnswers1.answer1;
  27.     var quest1Answer2:String = test.questions.questionAnswers1.answer2;
  28.     var quest1Answer3:String = test.questions.questionAnswers1.answer3;
  29.     var quest1CorrectAnswer:String = test.questions.questionAnswers1.correctAnswer;
  30.     var quest1Answers:Array = [quest1Answer1, quest1Answer2, quest1Answer3, quest1CorrectAnswer];
  31.    
  32.     //Answers for question 2
  33.     var quest2Answer1:String = test.questions.questionAnswers2.answer1;
  34.     var quest2Answer2:String = test.questions.questionAnswers2.answer2;
  35.     var quest2Answer3:String = test.questions.questionAnswers2.answer3;
  36.     var quest2CorrectAnswer:String = test.questions.questionAnswers2.correctAnswer;
  37.     var quest2Answers:Array = [quest2Answer1, quest2Answer2, quest2Answer3, quest2CorrectAnswer];
  38.    
  39.     //Answers for question 3
  40.     var quest3Answer1:String = test.questions.questionAnswers3.answer1;
  41.     var quest3Answer2:String = test.questions.questionAnswers3.answer2;
  42.     var quest3Answer3:String = test.questions.questionAnswers3.answer3;
  43.     var quest3CorrectAnswer:String = test.questions.questionAnswers3.correctAnswer;
  44.     var quest3Answers:Array = [quest3Answer1, quest3Answer2, quest3Answer3, quest3CorrectAnswer];
  45.    
  46.     //Answers for question 4
  47.     var quest4Answer1:String = test.questions.questionAnswers4.answer1;
  48.     var quest4Answer2:String = test.questions.questionAnswers4.answer2;
  49.     var quest4Answer3:String = test.questions.questionAnswers4.answer3;
  50.     var quest4CorrectAnswer:String = test.questions.questionAnswers4.correctAnswer;
  51.     var quest4Answers:Array = [quest4Answer1, quest4Answer2, quest4Answer3, quest4CorrectAnswer];
  52.    
  53.     //Answers for question 5
  54.     var quest5Answer1:String = test.questions.questionAnswers5.answer1;
  55.     var quest5Answer2:String = test.questions.questionAnswers5.answer2;
  56.     var quest5Answer3:String = test.questions.questionAnswers5.answer3;
  57.     var quest5CorrectAnswer:String = test.questions.questionAnswers5.correctAnswer;
  58.     var quest5Answers:Array = [quest5Answer1, quest5Answer2, quest5Answer3, quest5CorrectAnswer];
  59.    
  60.     //Answers for question 6
  61.     var quest6Answer1:String = test.questions.questionAnswers6.answer1;
  62.     var quest6Answer2:String = test.questions.questionAnswers6.answer2;
  63.     var quest6Answer3:String = test.questions.questionAnswers6.answer3;
  64.     var quest6CorrectAnswer:String = test.questions.questionAnswers6.correctAnswer;
  65.     var quest6Answers:Array = [quest6Answer1, quest6Answer2, quest6Answer3, quest6CorrectAnswer];
  66.    
  67.     var rndQuestions:String = questions[Math.floor(questions.length * Math.random())]; //randomising questions
  68.     var randomisedQuestions = String(rndQuestions); //storing random questions
  69.    
  70.     question.text = randomisedQuestions; //stores random questions in a text box
  71.    
  72.     //stores answers into three different text boxes on a specific question
  73.     if (question.text == questions[0]){
  74.         answer1.text = quest1Answers[0];
  75.         answer2.text = quest1Answers[1];
  76.         answer3.text = quest1Answers[2];
  77.     } else if(question.text == questions[1]){
  78.         answer1.text = quest2Answers[0];
  79.         answer2.text = quest2Answers[1];
  80.         answer3.text = quest2Answers[2];
  81.     } else if(question.text == questions[2]){
  82.         answer1.text = quest3Answers[0];
  83.         answer2.text = quest3Answers[1];
  84.         answer3.text = quest3Answers[2];
  85.     } else if(question.text == questions[3]){
  86.         answer1.text = quest4Answers[0];
  87.         answer2.text = quest4Answers[1];
  88.         answer3.text = quest4Answers[2];
  89.     } else if (question.text == questions[4]){
  90.         answer1.text = quest5Answers[0];
  91.         answer2.text = quest5Answers[1];
  92.         answer3.text = quest5Answers[2];
  93.     } else if (question.text == questions[5]){
  94.         answer1.text = quest6Answers[0];
  95.         answer2.text = quest6Answers[1];
  96.         answer3.text = quest6Answers[2];
  97.     }
  98.    
  99.     answer1Button.addEventListener(MouseEvent.CLICK, CheckQuestion1Answer);
  100.     function CheckQuestion1Answer(event:MouseEvent):void{
  101.         if (answer1.text == quest1Answers[3] || answer1.text == quest2Answers[3] || answer1.text == quest3Answers[3] ||
  102.             answer1.text == quest4Answers[3] || answer1.text == quest5Answers[3] || answer1.text == quest6Answers[3]){
  103.             //increments 1 to user score
  104.             tempScore++;
  105.             score =+ tempScore;
  106.             userScore.text = String(score);
  107.            
  108.             //stores randomised question
  109.             answeredQuestion1 = String(randomisedQuestions);
  110.             trace(answeredQuestion1);
  111.            
  112.             //checks to see if first randomised answered question is stored
  113.             if(answeredQuestion1 == 'First Question'){
  114.                 answeredQuestion2 = String(randomisedQuestions);
  115.                 trace(answeredQuestion2);
  116.             }
  117.            
  118.             //randomises questions
  119.             rndQuestions = questions[Math.floor(questions.length * Math.random())];
  120.             randomisedQuestions = String(rndQuestions);
  121.            
  122.             var rndQuestionCount:int = 0;
  123.            
  124.             while(randomisedQuestions != answeredQuestion1 && rndQuestionCount == 0 || randomisedQuestions != answeredQuestion2 && rndQuestionCount == 0){
  125.                 rndQuestions = questions[Math.floor(questions.length * Math.random())];
  126.                 randomisedQuestions = String(rndQuestions);
  127.                 rndQuestionCount++;
  128.             }
  129.            
  130.             question.text = randomisedQuestions;
  131.            
  132.         } else {
  133.             //increments -1 to user score
  134.             tempScore--;
  135.             score =+ tempScore;
  136.             userScore.text = String(score);
  137.             //randomises questions
  138.             rndQuestions = questions[Math.floor(questions.length * Math.random())];
  139.             randomisedQuestions = String(rndQuestions);
  140.             question.text = randomisedQuestions;
  141.         }
  142.        
  143.         //stores answers into three different text boxes on a specific question
  144.         if (question.text == questions[0]){
  145.             answer1.text = quest1Answers[0];
  146.             answer2.text = quest1Answers[1];
  147.             answer3.text = quest1Answers[2];
  148.         } else if(question.text == questions[1]){
  149.             answer1.text = quest2Answers[0];
  150.             answer2.text = quest2Answers[1];
  151.             answer3.text = quest2Answers[2];
  152.         } else if(question.text == questions[2]){
  153.             answer1.text = quest3Answers[0];
  154.             answer2.text = quest3Answers[1];
  155.             answer3.text = quest3Answers[2];
  156.         } else if(question.text == questions[3]){
  157.             answer1.text = quest4Answers[0];
  158.             answer2.text = quest4Answers[1];
  159.             answer3.text = quest4Answers[2];
  160.         } else if (question.text == questions[4]){
  161.             answer1.text = quest5Answers[0];
  162.             answer2.text = quest5Answers[1];
  163.             answer3.text = quest5Answers[2];
  164.         } else if (question.text == questions[5]){
  165.             answer1.text = quest6Answers[0];
  166.             answer2.text = quest6Answers[1];
  167.             answer3.text = quest6Answers[2];
  168.         }
  169.     }
  170.     answer2Button.addEventListener(MouseEvent.CLICK, CheckQuestion2Answer);
  171.     function CheckQuestion2Answer(event:MouseEvent):void{
  172.         if (answer2.text == quest1Answers[3] || answer2.text == quest2Answers[3] || answer2.text == quest3Answers[3] ||
  173.             answer2.text == quest4Answers[3] || answer2.text == quest5Answers[3] || answer2.text == quest6Answers[3]){
  174.             //increments 1 to user score
  175.             tempScore++;
  176.             score =+ tempScore;
  177.             userScore.text = String(score);
  178.             //randomises questions
  179.             rndQuestions = questions[Math.floor(questions.length * Math.random())];
  180.             randomisedQuestions = String(rndQuestions);
  181.             question.text = randomisedQuestions;
  182.         } else {
  183.             //increments -1 to user score
  184.             tempScore--;
  185.             score =+ tempScore;
  186.             userScore.text = String(score);
  187.             //randomises questions
  188.             rndQuestions = questions[Math.floor(questions.length * Math.random())];
  189.             randomisedQuestions = String(rndQuestions);
  190.             question.text = randomisedQuestions;
  191.         }
  192.        
  193.         //stores answers into three different text boxes on a specific question
  194.         if (question.text == questions[0]){
  195.             answer1.text = quest1Answers[0];
  196.             answer2.text = quest1Answers[1];
  197.             answer3.text = quest1Answers[2];
  198.         } else if(question.text == questions[1]){
  199.             answer1.text = quest2Answers[0];
  200.             answer2.text = quest2Answers[1];
  201.             answer3.text = quest2Answers[2];
  202.         } else if(question.text == questions[2]){
  203.             answer1.text = quest3Answers[0];
  204.             answer2.text = quest3Answers[1];
  205.             answer3.text = quest3Answers[2];
  206.         } else if(question.text == questions[3]){
  207.             answer1.text = quest4Answers[0];
  208.             answer2.text = quest4Answers[1];
  209.             answer3.text = quest4Answers[2];
  210.         } else if (question.text == questions[4]){
  211.             answer1.text = quest5Answers[0];
  212.             answer2.text = quest5Answers[1];
  213.             answer3.text = quest5Answers[2];
  214.         } else if (question.text == questions[5]){
  215.             answer1.text = quest6Answers[0];
  216.             answer2.text = quest6Answers[1];
  217.             answer3.text = quest6Answers[2];
  218.         }
  219.     }
  220.     answer3Button.addEventListener(MouseEvent.CLICK, CheckQuestion3Answer);
  221.     function CheckQuestion3Answer(event:MouseEvent):void{
  222.         if (answer3.text == quest1Answers[3] || answer3.text == quest2Answers[3] || answer3.text == quest3Answers[3] ||
  223.             answer3.text == quest4Answers[3] || answer3.text == quest5Answers[3] || answer3.text == quest6Answers[3]){
  224.             //increments 1 to user score
  225.             tempScore++;
  226.             score =+ tempScore;
  227.             userScore.text = String(score);
  228.             //randomises questions
  229.             rndQuestions = questions[Math.floor(questions.length * Math.random())];
  230.             randomisedQuestions = String(rndQuestions);
  231.             question.text = randomisedQuestions;
  232.         } else {
  233.             //increments -1 to user score
  234.             tempScore--;
  235.             score =+ tempScore;
  236.             userScore.text = String(score);
  237.             //randomises questions
  238.             rndQuestions = questions[Math.floor(questions.length * Math.random())];
  239.             randomisedQuestions = String(rndQuestions);
  240.             question.text = randomisedQuestions;
  241.         }
  242.        
  243.         //stores answers into three different text boxes on a specific question
  244.         if (question.text == questions[0]){
  245.             answer1.text = quest1Answers[0];
  246.             answer2.text = quest1Answers[1];
  247.             answer3.text = quest1Answers[2];
  248.         } else if(question.text == questions[1]){
  249.             answer1.text = quest2Answers[0];
  250.             answer2.text = quest2Answers[1];
  251.             answer3.text = quest2Answers[2];
  252.         } else if(question.text == questions[2]){
  253.             answer1.text = quest3Answers[0];
  254.             answer2.text = quest3Answers[1];
  255.             answer3.text = quest3Answers[2];
  256.         } else if(question.text == questions[3]){
  257.             answer1.text = quest4Answers[0];
  258.             answer2.text = quest4Answers[1];
  259.             answer3.text = quest4Answers[2];
  260.         } else if (question.text == questions[4]){
  261.             answer1.text = quest5Answers[0];
  262.             answer2.text = quest5Answers[1];
  263.             answer3.text = quest5Answers[2];
  264.         } else if (question.text == questions[5]){
  265.             answer1.text = quest6Answers[0];
  266.             answer2.text = quest6Answers[1];
  267.             answer3.text = quest6Answers[2];
  268.         }
  269.     }
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement