Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 22-08-2006, 11:22   #1 (permalink)
Neuer User
 
Registriert seit: Aug 2006
Beiträge: 1
mehrere Array's füllen

Hallo zusammen,
bin gerade dabei mich in AS einzuarbeiten und stosse an meine Grenzen.
In dem folgendem Script sollen mehrere Array's mit eindeutigen Zahlen gefüllt werden.
ein Array wird auch richtig gefüllt, die folgenden erhalten nur noch "undefined".

Wahrscheinlich liegt es daran,daß die Variablen an irgend einer "Stelle" nicht neu initalisiert werden oder so ähhnlich...wer kann mir einen Tip geben?
PHP-Code:
function init() {
    
function 
zufall() {
    var 
rand:Number=Math.floor(Math.random() *9)+1;
    return 
rand;
    }


    var 
anzahl:Number=0;
    var 
arr:Array = new Array(8);
    var 
arr1:Array = new Array(8);
    
    
    function 
vorhanden(zahl:Number,nArray:Array):Boolean {
        for (
i=0i<=8i++) {
            if (
zahl == nArray[i]) {  //prüft ob doppelt enthalten
                
return false//neu ziehen
            
}
        }
                return 
true;
                
    }
    
    function 
ziehen(_array:Array):Void {
        while(
anzahl<=8) {
        
this.zahl zufall();
        
this._array1 =_array;
            if (
vorhanden(zahl,_array)==true) {
                
_array1[anzahl]=zahl;
                
anzahl++;
            }
        }
    }


this.onEnterFrame = function() { 
    
ziehen(arr1); //Funktion aufrufen
    
ziehen(arr); //Funktion aufrufen
    
this.anzahl=0;
    
trace(arr);

    
    
A1.text arr[0];
    
A2.text arr[1];
    
A3.text arr[2];
    
A4.text arr[3];
    
A5.text arr[4];
    
A6.text arr[5];
    
A7.text arr[6];
    
A8.text arr[7];
    
A9.text arr[8];
    
    
B1.text arr1[0];
    
B2.text arr1[1];
    
B3.text arr1[2];
    
B4.text arr1[3];
    
B5.text arr1[4];
    
B6.text arr1[5];
    
B7.text arr1[6];
    
B8.text arr1[7];
    
B9.text arr1[8];
    
}

Vielen Dank im Vorraus
wolle2112 ist offline   Mit Zitat antworten
Alt 22-08-2006, 11:55   #2 (permalink)
angry > always
 
Benutzerbild von ingohill
 
Registriert seit: Jul 2001
Ort: NRW
Beiträge: 1.635
so?
ActionScript:
  1. Array.prototype.mischen = function () {
  2.     var rndTemp = new Array();
  3.     var temp    = new Array();
  4.     for (i=0; i<this.length; i++) {
  5.         rndTemp[i] = i;
  6.     }
  7.    
  8.     for (i=0; i<this.length; i++) {
  9.         pos = Math.floor(Math.random() * (rndTemp.length - .01));
  10.         temp[i] = this[rndTemp[pos]];
  11.         rndTemp.splice(pos, 1);
  12.     }
  13.    
  14.     for (i=0; i<this.length; i++) {
  15.         this[i] = temp[i];
  16.     }
  17. }
  18.  
  19. var a=new Array(0,1,2,3,4,5,6,7,8,9);
  20. trace(a);
  21. a.mischen();
  22. trace(a);
-ingo
__________________

on air: caliban | neaera | heaven shall burn | hatebreed | the agony scene
ingohill ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 22:43 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele