Denk jij nog een leuk of nuttig flash script te hebben, post het dan in de scriptbase !
array shuffle
Toegevoegd door: vinTage op 26-03-2007
bron
Beschrijving
Deze prototype mixed een array door elkaar en returned dezelfde array maar dan gehusselt.
Code
actionscript codeArray.prototype.shuffle = function(startIndex:Number, endIndex:Number) {
if (!startIndex) {
startIndex = 0;
}
if (!endIndex) {
endIndex = this.length-1;
}
for (var i:Number = endIndex; i>startIndex; i--) {
var randomNumber:Number = Math.floor(Math.random()*endIndex)+startIndex;
var tmp = this[i];
this[i] = this[randomNumber];
this[randomNumber] = tmp;
}
};
Gebruik
actionscript codevar myArray:Array = ["a", "b", "c", "d", "e"];
myArray.shuffle(); // Whole array is shuffled
trace(myArray);
var myArray:Array = ["a", "b", "c", "d", "e"];
myArray.shuffle(1, 3); // a and e are not moved
trace(myArray);
var myArray:Array = ["a", "b", "c", "d", "e"];
myArray.shuffle(1); // a is not moved
trace(myArray);
Je moet aangemeld zijn om commentaar te kunnen lezen of geven.