Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 01-12-2003, 20:38   #1 (permalink)
Neuer User
 
Registriert seit: Jan 2002
Ort: Wien / Perchtoldsdorf / Graz
Beiträge: 251
dynam.XML-Menü

Beim rumbasteln für einen neuen Entwurf für meine HP ist das hier entstanden und ich hab mir gedacht vielleicht kanns ja jemand brauchen. Es ist ein dynamisches XML-Menü. Ich muss allerdings zugeben dass es tlw.sicher etwas mühsam geskriptet ist. Liegt daran das ichs ned besser kann und außerdem noch keine Zeit zum optimieren hatte. Jegliche Form von Kritik und Verbesserungsvorschlägen sind daher willkommen!

Einfach folgendes Script ins erste Frame:

ActionScript:
  1. stop();
  2. function start() {
  3.     String.prototype.replace = function(sep, ins) {
  4.         return this.split(sep).join(ins);
  5.     };
  6.     news_format = new TextFormat();
  7.     news_format.size = 8;
  8.     news_format.font = "pixelFJ8pt1";
  9.     news_format.align = "left";
  10.     news_xml = new XML();
  11.     news_xml.ignoreWhite = true;
  12.     news_xml.load("news.txt");
  13.     news_xml.onLoad = function(status) {
  14.         if (status) {
  15.             create();
  16.         }
  17.     };
  18. }
  19. function create() {
  20.     news = news_xml.firstChild.childNodes;
  21.     for (i=0; news[i].attributes.title != undefined; i++) {
  22.         this.createEmptyMovieClip("news_box"+i, i+1);
  23.         with (this["news_box"+i]) {
  24.             beginFill(0x7498C8, 50);
  25.             moveTo(14, 15+i*12);
  26.             lineTo(138, 15+i*12);
  27.             lineTo(138, 25+i*12);
  28.             lineTo(14, 25+i*12);
  29.             endFill();
  30.             createTextField("news_root"+i, i+101, 14, 11+i*12, 116, 16);
  31.             set("news_root"+i+".selectable", false);
  32.             set("news_root"+i+".html", true);
  33.             set("news_root"+i+".htmlText", "<b>"+news[i].attributes.title+"</b>");
  34.             with (eval("news_root"+i)) {
  35.                 setTextFormat(news_format);
  36.             }
  37.         }
  38.         this["news_box"+i]._y = 0;
  39.         this["news_box"+i].id = i;
  40.         this["news_box"+i].onPress = function() {
  41.             expand(this.id);
  42.         };
  43.     }
  44. }
  45. start();
  46. function expand(active) {
  47.     breite = 124;
  48.     hoehe = 25+active*12;
  49.     q = 0;
  50.     this.onEnterFrame = function() {
  51.         expanding(active);
  52.     };
  53. }
  54. function expanding(active) {
  55.     for (i=0; news[i].attributes.title != undefined; i++) {
  56.         switch (true) {
  57.         case (i<active) :
  58.             this["news_box"+i]._y = this["news_box"+i]._y+(0-this["news_box"+i]._y)/10;
  59.             with (this["news_box"+i]) {
  60.                 clear();
  61.                 beginFill(0x7498C8, 50);
  62.                 moveTo(14, 15+i*12);
  63.                 lineTo(138, 15+i*12);
  64.                 lineTo(138, 25+i*12);
  65.                 lineTo(14, 25+i*12);
  66.                 endFill();
  67.                 news_root_content.removeTextField();
  68.             }
  69.             break;
  70.         case (i == active) :
  71.             this["news_box"+i]._y = this["news_box"+i]._y+(0-this["news_box"+i]._y)/10;
  72.             with (this["news_box"+i]) {
  73.                 createTextField("news_root_content", i+201, 14, 21+i*12, 390, 16);
  74.                 news_root_content.selectable = false;
  75.                 news_root_content.multiline = true;
  76.                 news_root_content.autosize = true;
  77.                 news_root_content.wordWrap = true;
  78.                 news_root_content.html = true;
  79.                 showing = new String(news[i].firstChild);
  80.                 showing = showing.replace("[bold]", "<b>");
  81.                 showing = showing.replace("[/bold]", "</b>");
  82.                 showing = showing.replace("[farbe#", "<font color='#");
  83.                 showing = showing.replace("[/farbe]", "</font>");
  84.                 showing = showing.replace("]", "'>");
  85.                 showing = news[i].attributes.date+"<br>"+showing;
  86.                 news_root_content.htmlText = showing.substring(0,q);
  87.                 if (showing.length+250 <= q) {
  88.                     delete this.onEnterFrame;
  89.                 } else {
  90.                     q = q+5;
  91.                 }
  92.                 with (news_root_content) {
  93.                     setTextFormat(news_format);
  94.                 }
  95.                 breite = breite+(406-breite)/10;
  96.                 hoehe = hoehe+(( 21+i*12+news_root_content._height)-hoehe)/5;
  97.                 clear();
  98.                 beginFill(0x7498C8, 50);
  99.                 moveTo(14, 15+i*12);
  100.                 lineTo(breite, 15+i*12);
  101.                 lineTo(breite, hoehe+10);
  102.                 lineTo(14, hoehe+10);
  103.                 endFill();
  104.             }
  105.             break;
  106.         case (i>active) :
  107.             this["news_box"+i]._y = this["news_box"+i]._y+(this["news_box"+active].news_root_content._height+6-this["news_box"+i]._y)/10;
  108.             with (this["news_box"+i]) {
  109.                 clear();
  110.                 beginFill(0x7498C8, 50);
  111.                 moveTo(14, 15+i*12);
  112.                 lineTo(138, 15+i*12);
  113.                 lineTo(138, 25+i*12);
  114.                 lineTo(14, 25+i*12);
  115.                 endFill();
  116.                 news_root_content.removeTextField();
  117.             }
  118.             break;
  119.         }
  120.     }
  121. }

aja und die datei news.txt die im gleichen Ordner liegen muss ist so aufgebaut:
Code:
<menu>
<news title="NEWS 1" date="16.11.2003">[farbe#dddddd]In farbe[/farbe]
[bold]fett[/bold].
oder ganz normal</news>
<news title="NEWS 2" date="22.11.2003">Update 1</news>
<news title="NEWS 3" date="22.11.2003">Update 2</news>
</menu>
name666 ist offline   Mit Zitat antworten
Alt 02-12-2003, 08:38   #2 (permalink)
_//\\#//\\_
 
Benutzerbild von warrantmaster
 
Registriert seit: Jan 2003
Beiträge: 7.060
hat was

xml ist cool, kann man schöne sachen ausbrüten.

einige kleine sachen:

bei klick auf aktiven (ausgefahrenen) button wär ein "wieder-einfahren " gut, um die sektion schließen zu können.
derzeit wird die funktion ausfahren nochmals abgearbeitet, sieht nicht gut aus.

positionierung über variablen, also nicht fest, am besten alles in einen mc, das ist dann wirklich flexibel.

allgemein würde ich die sache dynamischer handeln, also
die paint-funktion z.b ebenfalls mit variablen arbeiten lassen.

leg mal in die xml einen längeren content z.b. in news1,
bei klick auf den button schieben sich die beiden unteren
zu langsam nach unten, der link1 ist schon in voller größe
da, dann erst schieben sich die beiden unteren langsam
über link1 auf position.

sonst eine schöne idee, vor allem mit die textformatierung
ist nice.
bau mal noch ein wenig rum, das kann ein richtig schönes teil werden.


btw, ein link zum anschauen ist bei sowas immer gut

grz
warrantmaster ist offline   Mit Zitat antworten
Alt 06-12-2003, 13:01   #3 (permalink)
Neuer User
 
Registriert seit: Jan 2002
Ort: Wien / Perchtoldsdorf / Graz
Beiträge: 251
Hier mal wieder ein Update. Ich seh nur dass das ganze immer komplizierter wird, aber mir fällt ned wirklich was ein was ich vereinfachen könnte.Vielleicht hat der eine oder andere ne idee wie man das vereinfachen kann weil es is zur zeit glaub ich auch recht rechenintensiv. Ich hoffe es kann wer helfen.

zum anschaun

der code:
ActionScript:
  1. stop();
  2. function start() {
  3.     String.prototype.replace = function(sep, ins) {
  4.         return this.split(sep).join(ins);
  5.     };
  6.     news_format = new TextFormat();
  7.     news_format.size = 8;
  8.     news_format.font = "pixelFJ8pt1";
  9.     news_format.align = "left";
  10.     news_xml = new XML();
  11.     news_xml.ignoreWhite = true;
  12.     news_xml.load("news.txt");
  13.     news_xml.onLoad = function(status) {
  14.         if (status) {
  15.             create();
  16.         }
  17.     };
  18. }
  19. function draw(which, width, height) {
  20.     with (this["news_box"+which]) {
  21.         clear();
  22.         beginFill(0x7498C8, 50);
  23.         moveTo(14, 15+which*12);
  24.         lineTo(14+width, 15+which*12);
  25.         lineTo(14+width, height);
  26.         lineTo(14, height);
  27.         endFill();
  28.     }
  29. }
  30. function create() {
  31.     news = news_xml.firstChild.childNodes;
  32.     for (i=0; news[i].attributes.title != undefined; i++) {
  33.         this.createEmptyMovieClip("news_box"+i, i+1);
  34.         draw(i, 124, (25+i*12));
  35.         with (this["news_box"+i]) {
  36.             createTextField("news_root"+i, i+101, 14, 11+i*12, 116, 16);
  37.             set("news_root"+i+".selectable", false);
  38.             set("news_root"+i+".html", true);
  39.             set("news_root"+i+".htmlText", "<b>"+news[i].attributes.title+"</b>");
  40.             with (eval("news_root"+i)) {
  41.                 setTextFormat(news_format);
  42.             }
  43.         }
  44.         this["news_box"+i].id = i;
  45.         this["news_box"+i].q = 0;
  46.         this["news_box"+i].hoehe = 25+i*12;
  47.         this["news_box"+i].breite = 124;
  48.         this["news_box"+i].out = "false";
  49.         this["news_box"+i].onPress = function() {
  50.             if (this.out=="true") {
  51.                 this.out = "false";
  52.             } else {
  53.                 this.out = "true";
  54.             }
  55.             expand(this.id);
  56.         };
  57.     }
  58. }
  59. start();
  60. function expand(active) {
  61.     delete this.onEnterFrame;
  62.     this.onEnterFrame = function() {
  63.         for (x=0; news[x].attributes.title != undefined; x++) {
  64.             if (x != active) {
  65.                 this["news_box"+x].q = 0;
  66.                 this["news_box"+x].hoehe = 25+x*12;
  67.                 this["news_box"+x].breite = 124;
  68.                 this["news_box"+x].out = "false";
  69.             }
  70.         }
  71.         expanding(active);
  72.     };
  73. }
  74. function expanding(active) {
  75.     for (i=0; news[i].attributes.title != undefined; i++) {
  76.         switch (true) {
  77.         case (i<active) :
  78.             this["news_box"+i]._y = this["news_box"+i]._y+(0-this["news_box"+i]._y)/5;
  79.             draw(i, 124, (25+i*12));
  80.             this["news_box"+i].news_root_content.removeTextField();
  81.             break;
  82.         case (i == active) :
  83.             this["news_box"+i]._y = this["news_box"+i]._y+(0-this["news_box"+i]._y)/5;
  84.             with (this["news_box"+i]) {
  85.                 createTextField("news_root_content", i+201, 14, 21+i*12, 390, 16);
  86.                 news_root_content.selectable = false;
  87.                 news_root_content.multiline = true;
  88.                 news_root_content.autosize = true;
  89.                 news_root_content.wordWrap = true;
  90.                 news_root_content.html = true;
  91.                 showing = new String(news[i].firstChild);
  92.                 showing = showing.replace("[bold]", "<b>");
  93.                 showing = showing.replace("[/bold]", "</b>");
  94.                 showing = showing.replace("[farbe#", "<font color='#");
  95.                 showing = showing.replace("[/farbe]", "</font>");
  96.                 showing = showing.replace("]", "'>");
  97.                 showing = news[i].attributes.date+"<br>"+showing;
  98.                 news_root_content.htmlText = showing.substring(0, this["news_box"+i].q)+"<br><br>";
  99.                 with (news_root_content) {
  100.                     setTextFormat(news_format);
  101.                 }
  102.                 if (this["news_box"+i].out=="true") {
  103.                     if (showing.length+350<=this["news_box"+i].q) {
  104.                         delete this.onEnterFrame;
  105.                     } else {
  106.                         if (this["news_box"+i].q<0) {
  107.                             this["news_box"+i].q = 0;
  108.                         }
  109.                         this["news_box"+i].q = this["news_box"+i].q+5;
  110.                     }
  111.                     this["news_box"+i].breite = this["news_box"+i].breite+(392-this["news_box"+i].breite)/10;
  112.                     this["news_box"+i].hoehe = this["news_box"+i].hoehe+((21+i*12+news_root_content._height)-this["news_box"+i].hoehe)/5;
  113.                     draw(i, this["news_box"+i].breite, this["news_box"+i].hoehe);
  114.                 } else {
  115.                     if (0>=this["news_box"+i].q) {
  116.                         this["news_box"+i].news_root_content.removeTextField();
  117.                         createTextField("news_root_content", i+201, 14, 21+i*12, 124,4);
  118.                     }
  119.                     if (-350>=this["news_box"+i].q) {
  120.                         delete this.onEnterFrame;
  121.                     } else {
  122.                         if (this["news_box"+i].q>showing.length) {
  123.                             this["news_box"+i].q = showing.length;
  124.                         }
  125.                         this["news_box"+i].q = this["news_box"+i].q-5;
  126.                     }
  127.                     this["news_box"+i].breite = this["news_box"+i].breite+(news_root_content._width-this["news_box"+i].breite)/10;
  128.                     this["news_box"+i].hoehe = this["news_box"+i].hoehe+((21+i*12+news_root_content._height)-this["news_box"+i].hoehe)/5;
  129.                     draw(i, this["news_box"+i].breite, this["news_box"+i].hoehe);
  130.                 }
  131.             }
  132.             break;
  133.         case (i>active) :
  134.             this["news_box"+i]._y = this["news_box"+i]._y+((this["news_box"+active].news_root_content._height-4-this["news_box"+i]._y)/5);
  135.             draw(i, 124, (25+i*12));
  136.             this["news_box"+i].news_root_content.removeTextField();
  137.             break;
  138.         }
  139.     }
  140. }
name666 ist offline   Mit Zitat antworten
Alt 08-12-2003, 07:45   #4 (permalink)
funkdisziplin
 
Registriert seit: Jul 2003
Beiträge: 2.790
*Thumbs up*

sehr schöne idee ein collapsible XML-Menu zum darstellen von News zu verwenden! bin gespannt wie das weitergeht.

p.s. dein textformat wendet nicht an. bei mir wird der default-font displayed.

greets ddd
derdiedas ist offline   Mit Zitat antworten
Alt 09-12-2003, 21:06   #5 (permalink)
Neuer User
 
Registriert seit: Jan 2002
Ort: Wien / Perchtoldsdorf / Graz
Beiträge: 251
das mit der schrift sollte behoben sein, das kommt davon wenn man nur am eigenen pc testet wo die font natürlich is..

bin immer noch dankbar für hilfe wie ich diese furchtbar CPU-lastigen onEnterFrame 's vermeiden bzw. vereinfachen kann...
erwarte natürlich ned unbedingt kompette lösungen.nur tips und anregungen wie das prinzipiel ginge!
name666 ist offline   Mit Zitat antworten
Alt 31-12-2003, 13:45   #6 (permalink)
#no.991 @ MM
 
Benutzerbild von hugeinc
 
Registriert seit: Apr 2003
Ort: München
Beiträge: 327
Hi ho,
sorry, wenn ich erst jetzt antworte.
Habs grad erst gesehen.
Wenn es dir nichts ausmacht, würde ich an dem Teil nochwas "rumbasteln" und es dann ins Forum stellen.
Vorab ein paar Infos:
deine TXT würd ich als UTF-8 abspeichern (nicht Assci).
Wenn du die txt als xml umbenennst, können z.B. deine Zusatzeinträge wie [farbe... nicht gelesen werden.
Ich bastel grad auch noch an einer Geschichte, dass du dann extern über die XML das Aussehen noch bestimmen kannst.
Meld mich dann nächstes Jahr

Greets, Micha
__________________
Arbeit ist keine Lösung...
hugeinc 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 07:59 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele