arrays - Actionscript Game - Matching answers with Random Questions -


i'm beginner @ actionscript, there may simple explanation this, missing. appreciate on assignment.

i creating children's game user counts objects , picks number answer question asked. questions generate randomly. problem answers not match randomly generated questions.

this actionscript, "choice" answer buttons.

    import flash.events.mouseevent;         stop();  //------------------variables-----------------  var score = 0; var questionnum = 1; scoretxt.text = "0"; var randomnum:number;   var questions:array = ["how many orange flags there?",                        "how many blue flags there? ",                        "how many balls clown juggling?",                        "how many clouds in sky?",                         "how many horses on carousel?",                        "how many stripes on roof of tent?"]; var answers:array = [choice10, choice6, choice10, choice4, choice2, choice5];    //------------------display-----------------  choice1.visible = false; choice2.visible = false; choice3.visible = false; choice4.visible = false; choice5.visible = false; choice6.visible = false; choice7.visible = false; choice8.visible = false; choice9.visible = false; choice10.visible = false;   //------------------choice buttons-----------------  this.choice1.addeventlistener(mouseevent.click, this.nextq);             this.choice2.addeventlistener(mouseevent.click, this.nextq);             this.choice3.addeventlistener(mouseevent.click, this.nextq);             this.choice4.addeventlistener(mouseevent.click, this.nextq);             this.choice5.addeventlistener(mouseevent.click, this.nextq);             this.choice6.addeventlistener(mouseevent.click, this.nextq);             this.choice7.addeventlistener(mouseevent.click, this.nextq);             this.choice8.addeventlistener(mouseevent.click, this.nextq);             this.choice9.addeventlistener(mouseevent.click, this.nextq);             this.choice10.addeventlistener(mouseevent.click, this.nextq);  //------------------generate question-----------------  function generateq(){             this.randomnum = math.floor((math.random() * this.questions.length));             questiontxt.text = questions[randomnum];             this.questions.splice(this.randomnum, 1);}    //------------------start game-----------------  startgame_mc.addeventlistener(mouseevent.click, startgame);  function startgame(event:mouseevent){ generateq();  choice1.visible = true; choice2.visible = true; choice3.visible = true; choice4.visible = true; choice5.visible = true; choice6.visible = true; choice7.visible = true; choice8.visible = true; choice9.visible = true; choice10.visible = true; startgame_mc.visible=false; startscreen.visible=false; }   //------------------next question-----------------  function nextq(event:mouseevent){             this.questionnum++;             this.generateq();             trace(("questionnum" + this.questionnum));             if (this.questionnum == 6){                 trace("questions finished....");                 questiontxt.text = "all questions complete";             };              if(movieclip(event.target) == answers[randomnum]){         trace("right answer");                 score = (score + 5);                scoretxt.text = string(("score: " + string(score)));             }; } 

it's time learn multi-dimensional arrays or classes.

it seems problem here. if you're splicing questions array, should splice answers array 2 match up.

function generateq(){     randomnum = math.floor((math.random() * this.questions.length));     text = questions[randomnum];     questions.splice(this.randomnum, 1);      // add     this.questions.splice(this.randomnum, 1); } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -