Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var score:int = 0;
- //stroring questions
- nextButton.addEventListener(MouseEvent.CLICK, DeclareXMLVariables);
- function DeclareXMLVariables(event:MouseEvent):void{
- nextButton.visible = false;
- var tempScore:int = 0;
- //Storing answered questions
- var answeredQuestion1:String = 'First Question';
- var answeredQuestion2:String = 'Second Question';
- //All questions
- var question1:String = test.questions.questionAnswers1.question;
- var question2:String = test.questions.questionAnswers2.question;
- var question3:String = test.questions.questionAnswers3.question;
- var question4:String = test.questions.questionAnswers4.question;
- var question5:String = test.questions.questionAnswers5.question;
- var question6:String = test.questions.questionAnswers6.question;
- var questions:Array = [question1, question2, question3, question4,
- question5, question6]; //storing all questions from XML file
- //Answers for question 1
- var quest1Answer1:String = test.questions.questionAnswers1.answer1;
- var quest1Answer2:String = test.questions.questionAnswers1.answer2;
- var quest1Answer3:String = test.questions.questionAnswers1.answer3;
- var quest1CorrectAnswer:String = test.questions.questionAnswers1.correctAnswer;
- var quest1Answers:Array = [quest1Answer1, quest1Answer2, quest1Answer3, quest1CorrectAnswer];
- //Answers for question 2
- var quest2Answer1:String = test.questions.questionAnswers2.answer1;
- var quest2Answer2:String = test.questions.questionAnswers2.answer2;
- var quest2Answer3:String = test.questions.questionAnswers2.answer3;
- var quest2CorrectAnswer:String = test.questions.questionAnswers2.correctAnswer;
- var quest2Answers:Array = [quest2Answer1, quest2Answer2, quest2Answer3, quest2CorrectAnswer];
- //Answers for question 3
- var quest3Answer1:String = test.questions.questionAnswers3.answer1;
- var quest3Answer2:String = test.questions.questionAnswers3.answer2;
- var quest3Answer3:String = test.questions.questionAnswers3.answer3;
- var quest3CorrectAnswer:String = test.questions.questionAnswers3.correctAnswer;
- var quest3Answers:Array = [quest3Answer1, quest3Answer2, quest3Answer3, quest3CorrectAnswer];
- //Answers for question 4
- var quest4Answer1:String = test.questions.questionAnswers4.answer1;
- var quest4Answer2:String = test.questions.questionAnswers4.answer2;
- var quest4Answer3:String = test.questions.questionAnswers4.answer3;
- var quest4CorrectAnswer:String = test.questions.questionAnswers4.correctAnswer;
- var quest4Answers:Array = [quest4Answer1, quest4Answer2, quest4Answer3, quest4CorrectAnswer];
- //Answers for question 5
- var quest5Answer1:String = test.questions.questionAnswers5.answer1;
- var quest5Answer2:String = test.questions.questionAnswers5.answer2;
- var quest5Answer3:String = test.questions.questionAnswers5.answer3;
- var quest5CorrectAnswer:String = test.questions.questionAnswers5.correctAnswer;
- var quest5Answers:Array = [quest5Answer1, quest5Answer2, quest5Answer3, quest5CorrectAnswer];
- //Answers for question 6
- var quest6Answer1:String = test.questions.questionAnswers6.answer1;
- var quest6Answer2:String = test.questions.questionAnswers6.answer2;
- var quest6Answer3:String = test.questions.questionAnswers6.answer3;
- var quest6CorrectAnswer:String = test.questions.questionAnswers6.correctAnswer;
- var quest6Answers:Array = [quest6Answer1, quest6Answer2, quest6Answer3, quest6CorrectAnswer];
- var rndQuestions:String = questions[Math.floor(questions.length * Math.random())]; //randomising questions
- var randomisedQuestions = String(rndQuestions); //storing random questions
- question.text = randomisedQuestions; //stores random questions in a text box
- //stores answers into three different text boxes on a specific question
- if (question.text == questions[0]){
- answer1.text = quest1Answers[0];
- answer2.text = quest1Answers[1];
- answer3.text = quest1Answers[2];
- } else if(question.text == questions[1]){
- answer1.text = quest2Answers[0];
- answer2.text = quest2Answers[1];
- answer3.text = quest2Answers[2];
- } else if(question.text == questions[2]){
- answer1.text = quest3Answers[0];
- answer2.text = quest3Answers[1];
- answer3.text = quest3Answers[2];
- } else if(question.text == questions[3]){
- answer1.text = quest4Answers[0];
- answer2.text = quest4Answers[1];
- answer3.text = quest4Answers[2];
- } else if (question.text == questions[4]){
- answer1.text = quest5Answers[0];
- answer2.text = quest5Answers[1];
- answer3.text = quest5Answers[2];
- } else if (question.text == questions[5]){
- answer1.text = quest6Answers[0];
- answer2.text = quest6Answers[1];
- answer3.text = quest6Answers[2];
- }
- answer1Button.addEventListener(MouseEvent.CLICK, CheckQuestion1Answer);
- function CheckQuestion1Answer(event:MouseEvent):void{
- if (answer1.text == quest1Answers[3] || answer1.text == quest2Answers[3] || answer1.text == quest3Answers[3] ||
- answer1.text == quest4Answers[3] || answer1.text == quest5Answers[3] || answer1.text == quest6Answers[3]){
- //increments 1 to user score
- tempScore++;
- score =+ tempScore;
- userScore.text = String(score);
- //stores randomised question
- answeredQuestion1 = String(randomisedQuestions);
- trace(answeredQuestion1);
- //checks to see if first randomised answered question is stored
- if(answeredQuestion1 == 'First Question'){
- answeredQuestion2 = String(randomisedQuestions);
- trace(answeredQuestion2);
- }
- //randomises questions
- rndQuestions = questions[Math.floor(questions.length * Math.random())];
- randomisedQuestions = String(rndQuestions);
- var rndQuestionCount:int = 0;
- while(randomisedQuestions != answeredQuestion1 && rndQuestionCount == 0 || randomisedQuestions != answeredQuestion2 && rndQuestionCount == 0){
- rndQuestions = questions[Math.floor(questions.length * Math.random())];
- randomisedQuestions = String(rndQuestions);
- rndQuestionCount++;
- }
- question.text = randomisedQuestions;
- } else {
- //increments -1 to user score
- tempScore--;
- score =+ tempScore;
- userScore.text = String(score);
- //randomises questions
- rndQuestions = questions[Math.floor(questions.length * Math.random())];
- randomisedQuestions = String(rndQuestions);
- question.text = randomisedQuestions;
- }
- //stores answers into three different text boxes on a specific question
- if (question.text == questions[0]){
- answer1.text = quest1Answers[0];
- answer2.text = quest1Answers[1];
- answer3.text = quest1Answers[2];
- } else if(question.text == questions[1]){
- answer1.text = quest2Answers[0];
- answer2.text = quest2Answers[1];
- answer3.text = quest2Answers[2];
- } else if(question.text == questions[2]){
- answer1.text = quest3Answers[0];
- answer2.text = quest3Answers[1];
- answer3.text = quest3Answers[2];
- } else if(question.text == questions[3]){
- answer1.text = quest4Answers[0];
- answer2.text = quest4Answers[1];
- answer3.text = quest4Answers[2];
- } else if (question.text == questions[4]){
- answer1.text = quest5Answers[0];
- answer2.text = quest5Answers[1];
- answer3.text = quest5Answers[2];
- } else if (question.text == questions[5]){
- answer1.text = quest6Answers[0];
- answer2.text = quest6Answers[1];
- answer3.text = quest6Answers[2];
- }
- }
- answer2Button.addEventListener(MouseEvent.CLICK, CheckQuestion2Answer);
- function CheckQuestion2Answer(event:MouseEvent):void{
- if (answer2.text == quest1Answers[3] || answer2.text == quest2Answers[3] || answer2.text == quest3Answers[3] ||
- answer2.text == quest4Answers[3] || answer2.text == quest5Answers[3] || answer2.text == quest6Answers[3]){
- //increments 1 to user score
- tempScore++;
- score =+ tempScore;
- userScore.text = String(score);
- //randomises questions
- rndQuestions = questions[Math.floor(questions.length * Math.random())];
- randomisedQuestions = String(rndQuestions);
- question.text = randomisedQuestions;
- } else {
- //increments -1 to user score
- tempScore--;
- score =+ tempScore;
- userScore.text = String(score);
- //randomises questions
- rndQuestions = questions[Math.floor(questions.length * Math.random())];
- randomisedQuestions = String(rndQuestions);
- question.text = randomisedQuestions;
- }
- //stores answers into three different text boxes on a specific question
- if (question.text == questions[0]){
- answer1.text = quest1Answers[0];
- answer2.text = quest1Answers[1];
- answer3.text = quest1Answers[2];
- } else if(question.text == questions[1]){
- answer1.text = quest2Answers[0];
- answer2.text = quest2Answers[1];
- answer3.text = quest2Answers[2];
- } else if(question.text == questions[2]){
- answer1.text = quest3Answers[0];
- answer2.text = quest3Answers[1];
- answer3.text = quest3Answers[2];
- } else if(question.text == questions[3]){
- answer1.text = quest4Answers[0];
- answer2.text = quest4Answers[1];
- answer3.text = quest4Answers[2];
- } else if (question.text == questions[4]){
- answer1.text = quest5Answers[0];
- answer2.text = quest5Answers[1];
- answer3.text = quest5Answers[2];
- } else if (question.text == questions[5]){
- answer1.text = quest6Answers[0];
- answer2.text = quest6Answers[1];
- answer3.text = quest6Answers[2];
- }
- }
- answer3Button.addEventListener(MouseEvent.CLICK, CheckQuestion3Answer);
- function CheckQuestion3Answer(event:MouseEvent):void{
- if (answer3.text == quest1Answers[3] || answer3.text == quest2Answers[3] || answer3.text == quest3Answers[3] ||
- answer3.text == quest4Answers[3] || answer3.text == quest5Answers[3] || answer3.text == quest6Answers[3]){
- //increments 1 to user score
- tempScore++;
- score =+ tempScore;
- userScore.text = String(score);
- //randomises questions
- rndQuestions = questions[Math.floor(questions.length * Math.random())];
- randomisedQuestions = String(rndQuestions);
- question.text = randomisedQuestions;
- } else {
- //increments -1 to user score
- tempScore--;
- score =+ tempScore;
- userScore.text = String(score);
- //randomises questions
- rndQuestions = questions[Math.floor(questions.length * Math.random())];
- randomisedQuestions = String(rndQuestions);
- question.text = randomisedQuestions;
- }
- //stores answers into three different text boxes on a specific question
- if (question.text == questions[0]){
- answer1.text = quest1Answers[0];
- answer2.text = quest1Answers[1];
- answer3.text = quest1Answers[2];
- } else if(question.text == questions[1]){
- answer1.text = quest2Answers[0];
- answer2.text = quest2Answers[1];
- answer3.text = quest2Answers[2];
- } else if(question.text == questions[2]){
- answer1.text = quest3Answers[0];
- answer2.text = quest3Answers[1];
- answer3.text = quest3Answers[2];
- } else if(question.text == questions[3]){
- answer1.text = quest4Answers[0];
- answer2.text = quest4Answers[1];
- answer3.text = quest4Answers[2];
- } else if (question.text == questions[4]){
- answer1.text = quest5Answers[0];
- answer2.text = quest5Answers[1];
- answer3.text = quest5Answers[2];
- } else if (question.text == questions[5]){
- answer1.text = quest6Answers[0];
- answer2.text = quest6Answers[1];
- answer3.text = quest6Answers[2];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement