Actionscript 3 在Flash ActionScript 3中,我将如何编写一个从12个随机帧中选择5个帧的语句?

Actionscript 3 在Flash ActionScript 3中,我将如何编写一个从12个随机帧中选择5个帧的语句?,actionscript-3,flash,random,Actionscript 3,Flash,Random,我相信这个问题已经被无数次地问过了,但无论如何我都会感谢你的帮助。我正在制作一个FlashMasterMind克隆,有一个电影剪辑,里面有12个彩色的“钉子”和一个“洞”的图像。我该如何编写一个语句来选择五个随机帧,而不仅仅是前五个帧?我有最简单的想法,但我不完全确定它是否正确: var totalColors:Number = 12; var maxColors:Number = 5; var chosenColors:Array: for(var i:Number = 1; i<to

我相信这个问题已经被无数次地问过了,但无论如何我都会感谢你的帮助。我正在制作一个FlashMasterMind克隆,有一个电影剪辑,里面有12个彩色的“钉子”和一个“洞”的图像。我该如何编写一个语句来选择五个随机帧,而不仅仅是前五个帧?我有最简单的想法,但我不完全确定它是否正确:

var totalColors:Number = 12;
var maxColors:Number = 5;
var chosenColors:Array:

for(var i:Number = 1; i<totalColors; i++)
{
    chosenColors[i] = Math.floor(Math.random()*totalColors)+1
}
我很抱歉,如果这对一些人来说是基本的;我不是最强的程序员,尤其是在制作游戏时。我在ASP.NET和UI设计方面做得更好,但游戏开发总是因为一些奇怪的,可能是疯狂的原因吸引着我。无论如何,这里是创建新宝石方法的一部分。两个for循环是pan从12个随机帧中选择7个帧的代码。不幸的是,电影仍然从电影剪辑中选取前七帧

//i goes through all of the possible colors and adds them to the temp array
for (var i:uint = 1; i <= newPiece.totalFrames; i++)
{
    temp.push(i);
}

//j chooses seven colors out of the array of all possibilities
for (var j:int = 0; j < numPieces; j++)
{
    //index is the frame that has been chosen randomly
    var index:int = int(Math.random() * temp.length);
    chosenColors.push(j);
    chosenColors[j] = temp[index];

    //remove the index
    temp.splice(index, 0);
}

newPiece.type = Math.ceil(Math.random() * chosenColors.length);
//我检查了所有可能的颜色,并将它们添加到临时数组中
对于(变量i:uint=1;i
var totalColors:Number=12;
var maxColors:Number=5;
var chosenColors:Array=[];
var-temp:Array=[];

for(var i:Number=1;我已经在我之前制作的一个正在工作的Bejeweld克隆中实现了您的代码。只要我将这一行保留在您的第二个for循环中,我就没有编译时或运行时错误:但这并没有限制可以使用多少种类型的gem。我哪里出错了?您说的“限制可以使用多少种类型的gem”是什么意思?
//i goes through all of the possible colors and adds them to the temp array
for (var i:uint = 1; i <= newPiece.totalFrames; i++)
{
    temp.push(i);
}

//j chooses seven colors out of the array of all possibilities
for (var j:int = 0; j < numPieces; j++)
{
    //index is the frame that has been chosen randomly
    var index:int = int(Math.random() * temp.length);
    chosenColors.push(j);
    chosenColors[j] = temp[index];

    //remove the index
    temp.splice(index, 0);
}

newPiece.type = Math.ceil(Math.random() * chosenColors.length);
var totalColors:Number = 12;
var maxColors:Number = 5;   
var chosenColors:Array = [];
var temp:Array = [];

for(var i:Number = 1; i <= totalColors; i++)
{
    temp.push(i);
}

for (var j:int = 0; j < maxColors; j++)
{

   var index:int = int(Math.random()*temp.length);
   chosenColors[j] = temp[index];

   //remove the index
   temp.splice(index, 1);
}