Revision: 80594
Updated URL
Updated Code
Updated Description
at March 21, 2020 22:54 by chrisaiv
Updated URL
Updated Code
https://www.chrisjmendez.com/2007/02/21/as1-swap-numbers/
Updated Description
Needed a way to mix up the order of questions and answers for a Flash quiz. https://www.chrisjmendez.com/2007/02/21/as1-swap-numbers/
Revision: 2453
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 21, 2007 14:27 by chrisaiv
Initial Code
MovieClip.prototype.swapNumbers = function(numOfDigits:Number) { //1. Construct a temporary array var newOrder:Array = new Array(); //2. Build a condition where the array must have a specified number of digits while (newOrder.length != numOfDigits) { var skipNum:Boolean = false; //a. Generate a random number var randNum:Number = Math.ceil(Math.random() * numOfDigits); trace("Random Number Picked: " + randNum); //b. Run through the array.length and make sure there are no doubles for (var p:Number = 0; p < newOrder.length; p++){ if (newOrder[p] == randNum) { skipNum = true; } } //c. If the randNum is unique to the array, then push it into the array if (skipNum == false) { newOrder.push(randNum); } } //3. Once the array has the right mount of swapped digits, return the array return newOrder; }; var quizOrder:Array = this.swapNumbers(12); trace(quizOrder);
Initial URL
Initial Description
Needed a way to mix up the order of questions and answers for a Flash quiz.
Initial Title
AS1: Swap Numbers
Initial Tags
actionscript, flash
Initial Language
ActionScript