Prototype: Array.rand [Flash 8]
| 01.07.2003, 23:37 | | Beiträge: 6940 Wohnort: München Registriert: Jan 2002
| Prototype: Array.rand Liefert einen oder mehrere zufällige Einträge eines Arrays
Prototype:
ActionScript:1 2 3 4 5 6 7 8 9 10 11 | Array.prototype.rand = function(nr,i,temp_ary,temp_ary_2) {
if(temp_ary.length == undefined) {
var i = 0, temp_ary = [], temp_ary_2 = [];
for(var j in this) temp_ary_2.push(this[j]);
}
i++;
if(i<temp_ary_2.length && i<nr) temp_ary_2.rand(nr,i,temp_ary,temp_ary_2);
temp_ary.push(temp_ary_2.splice(random(temp_ary_2.length),1));
return temp_ary;
}
ASSetPropFlags(Array.prototype,"rand",1,1);
|
Beispiel Aufruf:
ActionScript:1 2 3 4 | test_ary = ["eins","zwei","drei","vier","fünf"];
// Die 3 ist optional und gibt die gewünschte Anzahl der Einträge an die ausgegeben werden sollen
trace(test_ary.rand(3));
|
Flex Freelancer || Flashhilfe @ Twitter || XING Profil | |
| | Themen Ähnliche Beiträge zum Thema | 11.04.2011 - campino1611 21.01.2010 - greenboy 16.06.2010 - skoda 16.07.2009 - mikelchris |
|
Flashhilfe.de Flash Platform Tipps & Tutorials Flash Platform Andere Programmiersprachen Jobangebote Diskussionen
Flashhilfe News 
Regeln & Bedingungen
|