Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 19-08-2003, 15:49   #1 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
kleine Array Frage

Moin !
Hab mal ne kleine Frage, hoffe jemand könnte mir weiterhelfen..
Also:

Ich habe im 1. Frame ein Array ...
Was muß ich tun, damit ich auf alles im 2.Frame in eine Funtion zugreifen kann ?
_global / this /root oder sowas hab die Zusammenhänge noch nicht so raus ...
und könnte ich in den for Schleifen immer die Gleichen Vars nehmen ? r für r1
[AS]
var kreise = new Array(7);
for (var r = 1; r<=7; ++r) {
kreise[r] = new Array(24);
for (var rr = 0; rr<=24; ++rr) {
kreise[r][rr] = new Array(4);
}
}
for (var r1 = 1; r1<=7; ++r1) {
for (var rr2 = 6; rr2<=18; rr2 += 12) {
kreise[r1][rr2][0] = false;
kreise[r1][rr2][1] = false;
}
}

///2.Frame
movieclip.prototype.Segmentvergebung= function(){
trace("kreise"+ kreise[1][6][1]);
}
/[AS]


gruß apfel 007
apfel007 ist offline   Mit Zitat antworten
Alt 19-08-2003, 15:57   #2 (permalink)
Flash-Wüstling
 
Benutzerbild von pheidrias
 
Registriert seit: Dec 2001
Ort: Halle/Saale
Beiträge: 4.300
Hi apfel007 !

Eigentlich müßte der Array auch in Frame 2 existieren !
Wenn du allerdings eine Funktion für MovieClip.prototype definierst, wird sie immer im "Kontext" des MCs ausgeführt, in dem du sie definiert hast. Also würde kreise[...] (entspricht this.kreise[...]) kreise im MC suchen...

Am besten wäre es, den Array auf _root zu legen --> dann kannst du ihn immer eindeutig via _root.kreise referenzieren.

_global finde ich nicht so gut --> da hast du den Array einfach überall verfügbar und er stört dich unter Umständen.

Also : _root ist der absolute Hauptfilm. Wenn du in Frame 1 im Hauptfilm this schreibst, entspricht das in diesem Falle _root. Wenn du in einem MC this schreibst, ist das dann der MC selber...

Da die Schleife unabhängig voneinander sind, empfiehlt sich, den gleichen Var-Namen zu wählen --> r wird ja dann immer wieder genau definiert...

tanti saluti,
pheidrias
__________________
Ehrlich währt am LÄNGSTEN !
pheidrias ist offline   Mit Zitat antworten
Alt 19-08-2003, 16:19   #3 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
Dankeschön, für die Ausführung..

Also ich habe mal this.kreise... geschrieben.
Abruf klappt im 1. Frame..
im 2. nicht
wie muß ich das array den in der Funktion ansprechen _root_this.kreise...??


gruß apfel 007
apfel007 ist offline   Mit Zitat antworten
Alt 19-08-2003, 17:04   #4 (permalink)
Flash-Wüstling
 
Benutzerbild von pheidrias
 
Registriert seit: Dec 2001
Ort: Halle/Saale
Beiträge: 4.300
im ersten als _root.kreise definieren und dann in der Funktion auf _root.kreise.

tanti saluti,
pheidrias
__________________
Ehrlich währt am LÄNGSTEN !
pheidrias ist offline   Mit Zitat antworten
Alt 20-08-2003, 08:49   #5 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
Danke, pheidrias
werds mal probieren!

gruß apfel007
apfel007 ist offline   Mit Zitat antworten
Alt 20-08-2003, 09:19   #6 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
3.Element im 2.frame

also das mit dem _root läuft..
Ich kann aber immer noch nicht auf das 3.Element kreise[1][2][3] in der Funktion zugreifen?! Das 2. kann ich auslesen.. warum nicht das 3. ?
Im 1. Frame läuft alles ganz normal !

gruß apfel007

Geändert von apfel007 (20-08-2003 um 14:23 Uhr)
apfel007 ist offline   Mit Zitat antworten
Alt 20-08-2003, 14:28   #7 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
Warum bloß

komme nicht dahinter!!
wrum kann ich das 3. Element im 2.Frame nicht auslesen ??
apfel007 ist offline   Mit Zitat antworten
Alt 20-08-2003, 16:24   #8 (permalink)
Flash-Wüstling
 
Benutzerbild von pheidrias
 
Registriert seit: Dec 2001
Ort: Halle/Saale
Beiträge: 4.300
weil für die letzte Schleife auch noch das new Array fehlt !

Du weist [0] und [1] direkt zu, ohne vorher ein Objekt oder Array erzeugt zu haben !

tanti saluti,
pheidrias
__________________
Ehrlich währt am LÄNGSTEN !
pheidrias ist offline   Mit Zitat antworten
Alt 20-08-2003, 17:07   #9 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
_root.kreise = new Array();
for (var r = 1; r<=7; ++r) {
_root.kreise[r] = new Array();
for (var rr = 0; rr<=24; ++rr) {
_root.kreise[r][rr] = new Array(4); //<--------
}
}

Hi pheidrias !
Ist das array so also noch nicht korrekt angelegt ?

gruß apfel 007
apfel007 ist offline   Mit Zitat antworten
Alt 20-08-2003, 17:48   #10 (permalink)
Flash-Wüstling
 
Benutzerbild von pheidrias
 
Registriert seit: Dec 2001
Ort: Halle/Saale
Beiträge: 4.300
stimmt - hatte ich übersehen...

Poste noch mal den gesamten Code, den du jetzt hast.

In Frame 1 geht das Ansprechen und in Frame 2 nicht ?

tanti saluti,
pheidrias
__________________
Ehrlich währt am LÄNGSTEN !
pheidrias ist offline   Mit Zitat antworten
Alt 20-08-2003, 18:08   #11 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
Stimmt

Danke für Deine Mühe!
Werde morgen den Code posten !

schönen Feierabend
Apfel007
apfel007 ist offline   Mit Zitat antworten
Alt 21-08-2003, 09:58   #12 (permalink)
Neuer User
 
Benutzerbild von apfel007
 
Registriert seit: May 2003
Ort: Hamburg
Beiträge: 161
Der Code

Frame 1

ActionScript:
  1. _root.kreise = new Array(7);
  2. for (var r = 1; r<=7; ++r) {
  3.     _root.kreise[r] = new Array(24);
  4.     for (var rr = 0; rr<=24; ++rr) {
  5.         kreise[r][rr] = new Array(4);
  6.     }
  7. }
  8. ////// 6 und 18 keine Waagerechte
  9. for (var r1 = 1; r1<=7; ++r1) {
  10.     for (var rr2 = 6; rr2<=18; rr2 += 12) {
  11.         kreise[r1][rr2][0] = "hallo";
  12.         kreise[r1][rr2][1] = false;
  13.     }
  14. }
  15. for (var rr1 = 0; rr1<=24; ++rr1) {
  16.     /////// kreis1  pos1 gsperrt wegen außenbahn !
  17.     kreise[1][rr1][1] = false;

Frame2
ActionScript:
  1. movieclip.prototype.Segmentvergebung = function(kreise) {
  2.         //// 61 Gesamt
  3.     // 1. Startpunkt funktion
  4.  
  5.    
  6. this.krPunktP = this.krPunkt +1;
  7. this.krPunktM = this.krPunkt -1;
  8.  
  9.     if(this.krRing > 2 ){ 
  10.             this.krRingP = this.krRing;}  // Bogen 3 p4 = 10 uew
  11.         else{
  12.             this.krRingP = this.krRing +1;
  13.             }
  14.    
  15.     if(this.krRing != 1){ 
  16.             this.krRingM = this.krRing -1;}
  17.         else{
  18.         this.krRingM = this.krRing;
  19.         }
  20.        
  21.        
  22.    trace("krRingP_"+this.krRingP);
  23.     trace("krRing_M"+this.krRingM);
  24.         //this.krRingP  }///////////// Achtung Fälle machen
  25.     //this.krRingP = this.krRing + 1;
  26.     ////this.krRingM = this.krRing -1 ; ///// Wenn KR 1
  27.  
  28.     this.j= 1;
  29.     this.jk= 1;
  30.     for (this.i = 0; this.i <= 3; ++this.i){   /// Knoten durchlauf  i 0 Knoten 01-1 gerde 02 -3 bogen   i01
  31.     trace(" this z"+ i);
  32.  
  33.     if (this.kreise[this.krRing][this.krPunkt][this.i] > 4 || this.kreise[this.krRing][this.krPunkt][this.i] == null ){ /// is was frei?!
  34.    
  35.     if ( this.i <= 1) {  /// Gerade
  36.                     trace(" Gerade");
  37.                     if (this.kreise[this.krRingP][this.krPunkt][this.i] > 4 || this.kreise[this.krRingP][this.krPunkt][this.i] == null ){   //// Test ein Bogen weiter
  38.                     trace(" Gerade bogen rauf");
  39.                     this.notiz[this.j][this.jk] = this.krRingP ;    // Ring start / Startpunkt / knoten
  40.                     trace(" Gerade_Notizzwischen "+ this.notiz[this.j][this.jk]);
  41.                     this.jk += 1;
  42.                    
  43.                     if (this.krRing > 2 && this.krPunkt <= 12 ) {
  44.                         this.krPunkt312 - this.krPunkt;
  45.                         this.notiz[this.j][this.jk] = this.krPunkt3;}
  46.                     else{
  47.                         this.notiz[this.j][this.jk] = this.krPunkt;}
  48.                     this.jk += 1;
  49.                     this.notiz[this.j][this.jk] = this.i;
  50.                     ++this.j;
  51.                     }
  52.                     if (this.kreise[this.krRingM][this.krPunkt][i] > 4 || this.kreise[this.krRingP][this.krPunkt][i] == null ){  // Test ein Bogen runter
  53.                         this.jk= 1;
  54.                         trace(" iii"+this.i);
  55.                         trace(" Gerade bogen runter");
  56.                         trace("jk "+this.jk);
  57.                     this.notiz[this.j][this.jk] = this.krRingM ;
  58.                     trace(" Gerade_Notiz"+ this.notiz[this.j][this.jk]);
  59.                     ++this.jk;
  60.                     this.notiz[this.j][this.jk] = this.krPunkt;
  61.                     ++this.jk;
  62.                     this.notiz[this.j][this.jk] = this.i;
  63.                     ++this.j;
  64.                     }
  65.                     trace("jk "+this.jk);
  66.                    
  67.                     }// gerade
  68.     else if ( this.i >= 2) {  ///Bogen
  69.     trace("Bogen");
  70.                     if (this.kreise[this.krRing][this.krPunktP][this.i] > 4 || this.kreise[this.krRing][this.krPunktP][this.i] == null ){   //// Test ein Bogen weiter
  71.                     this.jk= 1;
  72.                     this.notiz[this.j][this.jk] = this.krRing ;
  73.                     ++this.jk;
  74.                     this.notiz[this.j][this.jk] = this.krPunktP;
  75.                     ++this.jk;
  76.                     this.notiz[this.j][this.jk] = this.i;
  77.                     ++this.j;
  78.                     trace ("JJJJJJ------------bogen1.bome  "+ this.j);
  79.                     }
  80.                     if (this.kreise[this.krRing][this.krPunktM][i] > 4 || this.kreise[this.krRing][this.krPunktM][i] == null ){  // Test ein Bogen runter
  81.                     this.jk= 1;
  82.                     this.notiz[this.j][this.jk] = this.krRing ;
  83.                     ++this.jk;
  84.                     this.notiz[this.j][this.jk] = this.krPunktM;
  85.                     ++this.jk;
  86.                     trace ("JJJJJJ------------bogen"+ this.jk);
  87.                     this.notiz[this.j][this.jk] = this.i;   // Knoten Zähler 0-3
  88.                     //++this.j; // weil letztes
  89.                     }
  90.                    
  91.                     trace("Notizbogen   "+ notiz[this.j][3]);
  92.     }
  93.                     }//Bogen
  94.        
  95.     } // for
  96.    
  97.     trace("jjjjj"+this.j);
  98.     this.jj = Math.Zufall(this.j-1, 1);    /// Welcher weg wird eingesclagen  j -1 wahrscheinlich
  99.    
  100.     _root.linedraw[1] =  this.notiz[this.jj];
  101.     //this.jj -= 1;
  102.     trace ("Line draw-----"+ _root.linedraw[1][3]);
  103.    
  104.     _root.kreise[_root.linedraw[1][1]][_root.linedraw[1][2]][_root.linedraw[1][3]] = true   ;  // mark knoten Start
  105.             trace("kreise 4er_________ "+ _root.kreise[_root.linedraw[1][1]][_root.linedraw[1][2]]);
  106.    
  107.     }; // Main
  108.    
  109.    
  110.    
  111.    
  112.    
  113. Math.Zufall = function(wert, bwert) {
  114.             trace(" Zufall läuft");
  115.             var zahl = Math.round(Math.random()*wert)+bwert;
  116.             return zahl;
  117. };
  118.  
  119. movieclip.prototype.makeLine = function(kreise) {
  120.     trace(" make line läuft !!!!!!!!!!!");
  121.    
  122.    
  123.     if (style == 1) {
  124.         lineStyle(6, 0xE41C, 50);
  125.     } else {
  126.         lineStyle(2, 0x00FF00, 100);
  127.     }
  128.     //////////Anfangspunkt finden !
  129.     this.krRing = Math.Zufall(2, 1);
  130.     /// 3 Ringe
  131.     this.krPunkt = Math.Zufall(23, 0);
  132.     ///23 punkte
  133.     if ((this.krPunkt & 1) == 1) {
  134.         //ungerade zahl
  135.         ++this.krPunkt;
  136.     }
  137.     else if (this.krPunkt == 23) {
  138.         --this.krPunkt;
  139.     }
  140.    
  141.             /////// Prüfen ob Segmnet frei ist  gitter[kreis][p] = false;
  142.         /* 
  143.                
  144.     this.xp01 = kreise[this.krRing][0];
  145.     this.yp01 = kreise[this.krRing][1];
  146.     this.Segmentvergebung();
  147.     //// Anfangspunkt
  148.     moveTo(this.xp01, this.yp01);
  149.    
  150.    
  151.        
  152. };
  153. makeLine();

So ich glaube das is der Code .. ist leider ein bißchen mehr !
Die Frage ist nur, warum man/ich nicht auf die letzten Elemente in kreise[][][x] in frame 2 zureifen kann ?

gruß apfel007
apfel007 ist offline   Mit Zitat antworten
Alt 21-08-2003, 22:02   #13 (permalink)
Flash-Wüstling
 
Benutzerbild von pheidrias
 
Registriert seit: Dec 2001
Ort: Halle/Saale
Beiträge: 4.300
Wink

hmmm...da blicke ich jetzt natürlich auch nicht durch .

Warum ist das überhaupt auf zwei Frames ?
Klappt es denn, wenn beides auf einem Frame liegt ?

Bin nach wie vor der Meinung, daß der Fehler nicht in "verschwindenden" Variablen sondern in der Logik steckt....

tanti saluti,
pheidrias
__________________
Ehrlich währt am LÄNGSTEN !
pheidrias 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 18:29 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele