Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 06-04-2004, 14:19   #1 (permalink)
Neuer User
 
Benutzerbild von Takuma
 
Registriert seit: Oct 2002
Ort: Köln
Beiträge: 147
Frage zu createEmptyMovieClip / dynamische Buttons

ich möchte eigentlich dynamisch buttons erstellen. diese bekommen ihre eigenschaften über arrays.
ich dachte mir es über createEmptyMovieClip zu realisieren. wie spreche ich den neu erstellten mc an? ich habe es über die übergebene variable, welche den instanznamen darstellt versucht, es hat aber nicht funktioniert.
Takuma ist offline   Mit Zitat antworten
Alt 06-04-2004, 14:22   #2 (permalink)
Neuer User
 
Benutzerbild von Takuma
 
Registriert seit: Oct 2002
Ort: Köln
Beiträge: 147
achso, hier das script:

ActionScript:
  1. grafik = new array();
  2. // xPos, yPos, breite, höhe, tiefe, name
  3. grafik[0] = [0,0,50,100,10,"grafik1"];
  4. _global.addGrafik = function(xPos,yPos,breite,hoehe,tiefe,name){
  5.     this.createEmptyMovieClip(name, tiefe);
  6.     name._x=xPos;
  7.     name._y=yPos;
  8.     name.width=breite;
  9.     name.height=hoehe;
  10.     trace(xPos);
  11.     pfad="_root."+name;
  12.     trace(pfad);
  13.     pfad.onRollOver=function(){trace("hallo")};
  14. }
  15. addGrafik(grafik[0][0],grafik[0][1],grafik[0][2],grafik[0][3],grafik[0][4],grafik[0][5]);
Takuma ist offline   Mit Zitat antworten
Alt 06-04-2004, 19:10   #3 (permalink)
Flashaholic
 
Benutzerbild von atothek
 
Registriert seit: Feb 2003
Ort: Berlin
Beiträge: 1.459
Du verwendest die variable als wär es eine referenz ist sie aber nicht es gibt zwei schreibweisen
1. mit referenz
ActionScript:
  1. pfad=this["_root."+name];
1. ohne referenz eval ähnlich
ActionScript:
  1. this[pfad].onRollOver=function(){trace("hallo")};

ich würde die erste variante nehmen und nebenbei bemerkt ist das alles ehe ein wenig konfus mit den Array usw. Ich schick noch nen gegenvorschlag

see ya
__________________
TVNEXT Solutions
atothek ist offline   Mit Zitat antworten
Alt 06-04-2004, 19:33   #4 (permalink)
Flashaholic
 
Benutzerbild von atothek
 
Registriert seit: Feb 2003
Ort: Berlin
Beiträge: 1.459
So nun ein kleiner gegenvorschlag zur
Struktur mit ein paar kommentaren

ActionScript:
  1. // Fkt zum zeichnen eines Vierecks
  2. this.square = function(pMc, pThick, pColor, pFillColor, pWidth, pHeight) {
  3.     //
  4.     pMc.lineStyle(pThick, pColor, 100);
  5.     pMc.beginFill(pFillColor, 100);
  6.     pMc.lineTo(pWidth, 0);
  7.     pMc.lineTo(pWidth, pHeight);
  8.     pMc.lineTo(0, pHeight);
  9.     pMc.lineTo(0, 0);
  10.     pMc.endFill();
  11. };
  12. // Fkt zum erzeugen der einzelnen Clips
  13. this.createButtonClip = function(pObj) {
  14.     // erzeugen des MC
  15.     this.createEmptyMovieClip(pObj.clipName, pObj.clipTiefe);
  16.     // lokale variable erzeugen und eine Refernz zuweisen
  17.     var refMc = this[pObj.clipName];
  18.     // kleine Fkt zum hineinzeichnen
  19.     this.square(refMc, pObj.lineThick, pObj.lineColor, pObj.fillColor, pObj.clipW, pObj.clipH);
  20.     // platzieren des clips
  21.     refMc._x = pObj.clipX;
  22.     refMc._y = pObj.clipY;
  23.     // event zuweisen
  24.     refMc.onRollOver = function() {
  25.         trace("jo! das geht");
  26.     };
  27. };
  28. // erzeugen eines neuen clipObjekts
  29. this.obj1 = new Object();
  30. this.obj1.clipName = "mc1";
  31. this.obj1.clipTiefe = 10;
  32. this.obj1.lineThick = 1;
  33. this.obj1.lineColor = 0x226699;
  34. this.obj1.fillColor = 0xff6699;
  35. this.obj1.clipW = 100;
  36. this.obj1.clipH = 16;
  37. this.obj1.clipX = 100;
  38. this.obj1.clipY = 200;
  39. // aufruf der Fkt zum erzeugen der clips
  40. this.createButtonClip(this.obj1);

Kannste dir makieren und ins erste Frame kopieren.

wenn Fragen dann einfach fragen

see ya
__________________
TVNEXT Solutions
atothek ist offline   Mit Zitat antworten
Alt 07-04-2004, 12:38   #5 (permalink)
Neuer User
 
Benutzerbild von Takuma
 
Registriert seit: Oct 2002
Ort: Köln
Beiträge: 147
super, vielen dank.
das array war da, weil ich extern variablen laden muß, welche die informationen für die vierecke haben.
das problem ist, dass es immer unterschiedlich viele sein können. hast du ne idee wie ich das einstellen kann, dass;

1. abgefragt wird, wieviele vierecke gezeichnet werden müssen und
2. er dann dynamisch die jeweiligen mit den dazugehörigen infos anlegt

und warum muß bei:

Zitat:
pfad=this["_root."+name];
this und die eckigen klammern dahin?

vielen dank nochmal!
Takuma ist offline   Mit Zitat antworten
Alt 07-04-2004, 13:12   #6 (permalink)
Flashaholic
 
Benutzerbild von atothek
 
Registriert seit: Feb 2003
Ort: Berlin
Beiträge: 1.459
Heute Abend setze ich mal ran zurzeit bin ich uff arbeit
__________________
TVNEXT Solutions
atothek ist offline   Mit Zitat antworten
Alt 08-04-2004, 21:09   #7 (permalink)
Flashaholic
 
Benutzerbild von atothek
 
Registriert seit: Feb 2003
Ort: Berlin
Beiträge: 1.459
so ich hab mal schnell eine kleine XML Variante gebastellt

die XML Struktur ist wie Folgt

PHP-Code:
<?xml version="1.0" ?>
<navigation>
    <items linethick="1" linecolor="0x000000" fillcolor="0xff6699" overcolor="0x0000ff">
        <item titel="navipunkt1" w="100" h="20" x="0" y="0" />
        <item titel="navipunkt2" w="100" h="20" x="0" y="22" />
        <item titel="navipunkt3" w="100" h="20" x="0" y="44" />
        <item titel="navipunkt4" w="100" h="20" x="0" y="66" />
    </items>

    <items linethick="1" linecolor="0x000000" fillcolor="0x006699" overcolor="0xff00ff">
        <item titel="navipunkt1" w="100" h="20" x="102" y="0" />
        <item titel="navipunkt2" w="100" h="20" x="102" y="22" />
    </items>

    <items linethick="1" linecolor="0x000000" fillcolor="0xff6699" overcolor="0x33ffff">
        <item titel="navipunkt1" w="100" h="20" x="204" y="0" />
        <item titel="navipunkt2" w="100" h="20" x="204" y="22" />
        <item titel="navipunkt3" w="100" h="20" x="204" y="44" />
        <item titel="navipunkt4" w="100" h="20" x="204" y="66" />
        <item titel="navipunkt5" w="100" h="20" x="204" y="88" />
        <item titel="navipunkt6" w="100" h="20" x="204" y="110" />
    </items>
</navigation>
und das passende ActionScript

ActionScript:
  1. // Fkt zum zeichnen eines Vierecks
  2. this.square = function(pMc, pThick, pColor, pFillColor, pWidth, pHeight) {
  3.     //
  4.     pMc.lineStyle(pThick, pColor, 100);
  5.     pMc.beginFill(pFillColor, 100);
  6.     pMc.lineTo(pWidth, 0);
  7.     pMc.lineTo(pWidth, pHeight);
  8.     pMc.lineTo(0, pHeight);
  9.     pMc.lineTo(0, 0);
  10.     pMc.endFill();
  11. };
  12. // Fkt zum erzeugen der einzelnen Clips
  13. this.createButtonClip = function(pObj) {
  14.     //
  15.     this.createEmptyMovieClip(pObj.clipName, pObj.clipTiefe);
  16.     var refMc = this[pObj.clipName];
  17.     //
  18.     this.square(refMc, pObj.lineThick, pObj.lineColor, pObj.fillColor, pObj.w, pObj.h);
  19.     //
  20.     refMc._x = pObj.x;
  21.     refMc._y = pObj.y;
  22.     refMc.obj = pObj;
  23.     refMc.parentObj = this;
  24.     //
  25.     refMc.onRollOver = function() {
  26.         //
  27.         this.clear();
  28.         this.parentObj.square(this, this.obj.lineThick, this.obj.lineColor, this.obj.overColor, this.obj.w, this.obj.h);
  29.     };
  30.     //
  31.     refMc.onRollOut = function() {
  32.         //
  33.         this.clear();
  34.         this.parentObj.square(this, this.obj.lineThick, this.obj.lineColor, this.obj.fillColor, this.obj.w, this.obj.h);
  35.     };
  36. };
  37. // Fkt um diverse xml dokument zu laden
  38. this.xmlLoader = function(pXmlFile, pXmlVar, pCallBack) {
  39.     //
  40.     this[pXmlVar] = new XML();
  41.     this[pXmlVar].ignoreWhite = true;
  42.     this[pXmlVar].parentObj = this;
  43.     this[pXmlVar].onLoad = function() {
  44.         //
  45.         this.parentObj[pCallBack]();
  46.     };
  47.     this[pXmlVar].load(pXmlFile);
  48. };
  49. // callback parser Fkt zum erzeugen der clips und der passenden Objekte
  50. this.naviXmlParser = function() {
  51.     //
  52.     var xml = this.naviData.firstChild.childNodes;
  53.     var mainLength = xml.length;
  54.     //
  55.     if (this.naviClipObj == undefined) {
  56.         this.naviClipObj = new Object();
  57.     }
  58.     //
  59.     var k = 0;
  60.     for (var i = 0; i<mainLength; i++) {
  61.         //
  62.         var subLength = xml[i].childNodes.length;
  63.         //
  64.         for (var j = 0; j<subLength; j++) {
  65.             //
  66.             var objTitel = "naviObj_"+i+"_"+j;
  67.             //
  68.             this.naviClipObj[objTitel] = new Object();
  69.             this.naviClipObj[objTitel].clipName = xml[i].childNodes[j].attributes.titel+"_"+i;
  70.             this.naviClipObj[objTitel].clipTiefe = k++;
  71.             this.naviClipObj[objTitel].lineThick = xml[i].attributes.linethick;
  72.             this.naviClipObj[objTitel].lineColor = xml[i].attributes.linecolor;
  73.             this.naviClipObj[objTitel].fillColor = xml[i].attributes.fillcolor;
  74.             this.naviClipObj[objTitel].overColor = xml[i].attributes.overcolor;
  75.             //
  76.             this.naviClipObj[objTitel].w = xml[i].childNodes[j].attributes.w;
  77.             this.naviClipObj[objTitel].h = xml[i].childNodes[j].attributes.h;
  78.             this.naviClipObj[objTitel].x = xml[i].childNodes[j].attributes.x;
  79.             this.naviClipObj[objTitel].y = xml[i].childNodes[j].attributes.y;
  80.             //
  81.             this.createButtonClip(this.naviClipObj[objTitel]);
  82.         }
  83.     }
  84. };
  85. this.xmlLoader("xmlNaviAndShape.xml", "naviData", "naviXmlParser");

so ich hab mir einstweilen erklärungen gespart wenn fragen sind immer stellen

see ya
__________________
TVNEXT Solutions

Geändert von atothek (09-04-2004 um 08:48 Uhr)
atothek ist offline   Mit Zitat antworten
Alt 08-04-2004, 21:12   #8 (permalink)
Flashaholic
 
Benutzerbild von atothek
 
Registriert seit: Feb 2003
Ort: Berlin
Beiträge: 1.459
Noch mal ne kleine zip zum runterladen
Angehängte Dateien
Dateityp: zip xmlnaviandshape.zip (6,0 KB, 8x aufgerufen)
__________________
TVNEXT Solutions

Geändert von atothek (09-04-2004 um 08:51 Uhr)
atothek 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 12:18 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele