选择随机元素的数组中的ActionScript 3 [英] Pick random Element of an Array Actionscript 3

查看:177
本文介绍了选择随机元素的数组中的ActionScript 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有影片剪辑的数组,我希望把他们在舞台上。所以他们必须是唯一的,随机选择的。

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];
}

这篇关于选择随机元素的数组中的ActionScript 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆