我有影片剪辑的数组,我希望把他们在舞台上。所以他们必须是唯一的,随机选择的。
I have an array of movieclips and i want to put them on stage. so they have to be unique and randomly chosen.
我该怎么办呢?
感谢您的时间
您可以用得到一个随机数的Math.random()
这将返回的0号和1。
You can get a random number using Math.random()
This will return a number between 0 and 1.
因此,获取数组的一个随机元素,使用这样的:
So, for getting a random element of the array, use this:
function getRandomElementOf(array:Array):Object {
var idx:int=Math.floor(Math.random() * array.length);
return array[idx];
}