private function randomSort(a:*, b:*):Number
{
return Math.random()>.5 ? -1 : 1;
}
private function myFunc():void
{
var myArrayToSort = [1,2,3,4,5];
myArrayToSort.sort(randomSort);
trace(MY ARRAY SORTED IS '+myArrayToSort)
}
Awesome way to randomly sort an array.
I'm using this with the sliver movie to randomly place the clips in various positions so every time you watch the movie it's different.
Pretty damned cool.
5/14/2008
oh the randomness
at 2:20 PM
Filed under: actionscript, adobe, programming
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment