AS3 - 从一个阵列被选中preventing重复 [英] AS3 - Preventing duplicates from being selected from an array

查看:155
本文介绍了AS3 - 从一个阵列被选中preventing重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有八串,我想(使用文本域)在舞台上放置一个随机顺序的数组。

I've got an array of eight strings that I want to place on the stage (using TextFields) in a random order.

我可以选择任意包含字符串的8没有问题,用的Math.random挑选了一批0-7之间,并把该项目的索引搬上了舞台。

I can select any 8 of the strings without a problem, using Math.random to pick a number between 0-7 and placing the item at that index onto the stage.

但我被添加奋力prevent重复。有没有人有什么建议?

But I'm struggling to prevent duplicates from being added. Does anyone have any suggestions?

感谢您

推荐答案

洗牌数组,然后通过它循环。一些很好的例子可以在这里找到:

Shuffle the array, then loop through it. Some great examples can be found here:

http://bost.ocks.org/mike/shuffle/

这篇关于AS3 - 从一个阵列被选中preventing重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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