Flashhilfe.de - Flash Community

Prototype: Array.rand [Flash 8]

Forum > Tipps & Tricks zu Flash, Flex und Adobe AIR > Prototype: Array.rand

 


AntwortenRegistrieren Seite1  

 01.07.2003, 23:37 
Benutzerbild von SebastianFlashhilfe.de Moderator
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
Schlagwörter: Array, prototype
 
Themen
Ähnliche Beiträge zum Thema
Würfeln mit Array [Flash 10] 11.04.2011 - campino1611
 

AntwortenRegistrieren Seite1  

Schnellantwort

Du musst registriert sein, um diese Funktion nutzen zu können.
Partner Webseiten: DesignerInAction.de   Designnation.de   Mediengestalter.info   php-resource.de   phpforum.de   phpwelt.de   Pixelio.de   PSD-Tutorials.de   Tutorials.de

Haftungsausschluss   Datenschutzerklärung   Hier Werben   Impressum
© 1999-2012 Sebastian Wichmann - Flashhilfe.de