ActionScript 3 数组 - 随机短路

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 数组 - 随机短路相关的知识,希望对你有一定的参考价值。

//first create your array with songs
var songsArray:Array = new Array();
songsArray.push("Various Artist - Song1.mp3");
//...etc
 
//next create random array
for (var i:int = 0; i < songsArray.length; i++) 
{
    pickArray[i] = i;
}
//and sort it with your custom sort function
pickArray.sort(randomSort);
 
function randomSort(elementA:Object, elementB:Object):int 
{
    return Math.random() * 10 - 5;
}
 
//let say playNextSong function is initiated 
//by the user clicking on "next" button
var counter:uint = 0;
function playNextSong(e:MouseEvent):void
{
	//pick some random song but make sure we won't go out of range
	counter = (counter == songsArray.length - 1) ? 0 : counter + 1;
	playSong(songsArray[pickArray[counter]]);
}

以上是关于ActionScript 3 数组 - 随机短路的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 随机播放数组

ActionScript 3 从数组中选择一个随机项

ActionScript 3 AS3随机化数组

ActionScript 3 随机化一个数组

ActionScript 3.0 随机化数组、显示数字并拼接该数字

ActionScript 3 有用的数组工具 - SHUFFLE,随机,删除,