The code below randomizes the order of some quiz answers, but I’ve decided that I need a version where the quiz answers are in a particular order.
I thought it would be easy to turn off the randomization by using the value from
answers.child("*").length()
to feed the array counter. Instead, the script runs slow and kills. If I trace the value of
answers.child("*").length() I get a countdown: 4 3 2 1. Seems simple enough, but the compiler hates using those number as is.
So I’m scratching my head - how should I simplify this array creation so that the answers are taken in order?
public function shuffleAnswers(answers:XMLList) {
var shuffledAnswers:Array = new Array;
while (answers.child("*").length() > 0) {
trace(answers.child("*").length()); // 4 3 2 1
var r:int = Math.floor(Math.random() * answers.child("*").length());
shuffledAnswers.push(answers.answer[r]);
delete answers.answer[r];
}
return shuffledAnswers;
}