Flash Quick Tip: How to randomize an Array
Posted in Flash | 2 Comments
I had to google this today so i though i would share it with you!
This snippet of actionscript can be used to simply re-order or randomize an array in Adobe Flash.
var myArray = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
myArray.sort(function (){
return Math.round(Math.random());
});
trace(myArray);
ps and yes i know I’ve spelt randomise wrong ; )
Tags: actionscript
You might also like:
July 10th, 2009 at 3:41 pm
on running the function the fist element is always 5. Why?
July 10th, 2009 at 3:48 pm
i have just created a new movie clip to test this and i have not found that it always starts with 5. It works perfectly for me!