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.
Leave a Reply
You must be logged in to post a comment.