flash cs3 - randomize/shuffle array item without repeat actionscript 3.0 -


i creating question , answer quiz using flash cs3 , actionscript 3.0. have large array of question, wish put xml document(can xml file reside in flash file itself?i thought ive seen did that.)

ok,my main problem shuffle questions without repeat until questions asked. have worked on tutorial,and great shuffling without repeat. http://www.flashandmath.com/howtos/deal/

but,i wish ask 1 question @ once. have looked option shuffle frames, think how can count score of quiz @ end of it?

so have edited codes according answer,

i want make button named "check" check if answer filled correct or wrong. , score increase if answer right. user hit button named "next" go next question.

the final score shown @ next frame, after questions finished. alright bring score counted next frame?

or, should make movie clip visible score when question ended?

check_btn.addeventlistener(mouseevent.click, checkanswer); next_btn.addeventlistener(mouseevent.click, nextquestion);

var index:int = 0;

var score:int = 0;

questions_txt.text = newquizmodel[index]["q"];

var useranswer:string = "";

function checkanswer(mouseevent):void{

useranswer = answers_txt.text;  if (useranswer == newquizmodel[index]["a"]) {     answers_txt.text = "";     score++; } else {     answers_txt.text = "";     score = score; }  index++; index%= quizmodel.length; nextquestion(index); 

}

function nextquestion(idx:int):void{

for(var i:int=0; i<newquizmodel.length; i++){      if(i == quizmodel.length - 1){         nextframe();     }     else{         questions_txt.text = newquizmodel[idx]["q"];} 

nextquestion(index);

the code @ next frame,

score_txt.text = score.tostring()+"/"+newquizmodel.length;

i have noticed user can fill answer again if answer wrong.how give score user's first try?

many :)

try this?

var quiz:array =  [   "1+1 = ?",   "5*5+5 = ?",   "10/5*5-4 = ?",   "12/6*6/12 = ?",   "13+10/5-13/2 = ?" ];  function shufflearray($arr:array):array {     var l:number = $arr.length - 1;      (var it:uint = 0; it<l; it++)     {         var r:int = math.round(math.random() * l);         var tmp:string = $arr[it];         $arr[it] = $arr[r];         $arr[r] = tmp;     }     return $arr; }  var refreshquiz:array = shufflearray(quiz);  trace(refreshquiz); 

so, why try show quiz frame frame? using actionscript code show. more simple , flexible. make quiz box textfield. , if user answer right, change text.

here skeleton code.

var quizmodel:array = [{q:"1+1 = ?", a:"2"}, {q:"5+5 = ?", a:"10"}, {q:"2+2 = ?", a:"4"}, {q:"6+6 = ?", a:"12"},{q:"8-7 = ?",a:"1"}];  var user_ans:array = new array(); var newquizmodel:array = shufflearray(quizmodel); stage.addeventlistener(keyboardevent.key_down, go);  function shufflearray(arr:array):array {     var l:number = arr.length - 1;      (var it:uint = 0; it<l; it++)     {         var r:int = math.round(math.random() * l);         var tmp:object = arr[it];         arr[it] = arr[r];         arr[r] = tmp;     }     return arr; }  var index:int = 0; questions_txt.text = newquizmodel[index]["q"]; var useranswer:string = ""; function go(k:keyboardevent):void {     if (k.keycode != keyboard.enter)     {         return;     }      useranswer = answers_txt.text;      if (useranswer == newquizmodel[index]["a"])     {         answers_txt.text = "your answer correct!";     }     else     {         answers_txt.text = "your answer wrong";         return;     }      index++;     index%= quizmodel.length;     showquiz(index); }  function showquiz(idx:int):void {     questions_txt.text = newquizmodel[idx]["q"]; }  showquiz(index); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -