如何在flash中創建一個數組as2,並從那裏選擇12個值將它們分配給十二個不同的變量?AS2數組隨機選擇
到目前爲止,我得到這個:
quotes = new Array();
quotes[0] = "one";
quotes[1] = "two";
quotes[2] = "three";
quotes[3] = "four";
quotes[4] = "five";
quotes[5] = "six";
quotes[6] = "seven";
quotes[7] = "eight";
quotes[8] = "nine";
quotes[9] = "ten";
quotes[10] = "eleven";
quotes[11] = "twelve";
quotes[12] = "thirteen";
quotes[13] = "fourteen";
quotes[14] = "fifteen";
quotes[15] = "sixteen";
quotes[16] = "seventeen";
quotes[17] = "eighteen";
quotes[18] = "nineteen";
quotes[19] = "twenty";
進出口保持這種結構,因爲它會更容易從長遠來看,保持並有更多的可讀性。
我不知道的是如何從中取出12個隨機值並將它們分配給變量。
好了,現在我已經加入這片:
trace(quotes)
for(var i:Number = 0; i<12; i++){
var x:Number = Math.floor((Math.random()*quotes.length));
trace("X :: " + x);
trace("ARRAY VALUE :: " + quotes[x]);
quotes.splice(x,1);
}
現在我看到在跟蹤12個不同的值,而無需重複。 但我仍然不知道如何使結果成爲12個不同變量的值。
`quotes [19] =「twenty」;`,也許? – 2010-12-22 13:15:31
upsie,小錯誤。 – Lopez 2010-12-22 13:17:23