1&1 DSL
Flashhilfe.de - Flash Community

Prototype: Array.shuffle [Flash 8]

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

 


AntwortenRegistrieren Seite1  

 01.07.2003, 23:34 
Benutzerbild von SebastianFlashhilfe.de Moderator
Beiträge: 6940
Wohnort: München
Registriert: Jan 2002

Prototype: Array.shuffle
Array in zufälliger Reihenfolge sortieren

Prototype:
ActionScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// ## Ohne Typ Umwandlung:  ############################

function rand() {
   return random(3)-1;
}

Array.prototype.shuffle = function() {
   return this.sort(rand);
}

ASSetPropFlags(Array.prototype,"shuffle",1,true);



// ## Typ Umwandlung: ############################

Array.prototype.shuffle = function() {
   var temp_ary = [];
   while(this.length) temp_ary.push(this.splice(random(this.length),1));
   return temp_ary;
}

ASSetPropFlags(Array.prototype,"shuffle",1,true);


Beispiel Aufruf:
ActionScript:
1
2
3
test_ary = ["eins","zwei","drei","vier","fünf"];
neues_ary = test_ary.shuffle();
trace(neues_ary)

Flex Freelancer || Flashhilfe @ Twitter || XING Profil
Schlagwörter: Array, prototype
 
Themen
Ähnliche Beiträge zum Thema
 

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