Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 09-10-2006, 15:37   #1 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
XML parsen?

Hallo,

ich versuche hier vergeblich eine XML Datei zu parsen:

Code:
<comments>

    <comment>
        <imgURL>img1</imgURL>
        <name>name1</name>
        <remark>remark1<remark>
    </comment>
  
    <comment>
        <imgURL>img2</imgURL>
        <name>name2</name>
        <remark>remark2</remark>
    </comment>
  
</comments>
Setze ich ein trace in die for Schleife, dann wird es nie ausgeführt. Woran kann das liegen? Die XML Datei wird geladen (onLoad ausgeführt).

ActionScript:
  1. public function onLoadXML(success:Boolean):Void {
  2.         if (success) {
  3.             var comments_xn:XMLNode = comments_xml.firstChild;
  4.             var comment_xn:XMLNode;
  5.             for (var i:Number = 0; i < comments_xn.childNodes.length; i++) {
  6.                 trace("test");
  7.                 comments[i] = new Object();
  8.                 comment_xn = comments_xn.childNodes[i];
  9.                 comments[i]['imgURL'] = comments_xn.childNodes[i].firstChild;
  10.                 comments[i]['name'] = comments_xn.childNodes[i].nextSibling;
  11.                 comments[i]['remark'] = comments_xn.childNodes[i].nextSibling;
  12.                 error = false;
  13.             }
  14.             super.notifyChanges();
  15.         } else {
  16.             error = true;
  17.         }
  18.     }
compuboy1010 ist offline   Mit Zitat antworten
Alt 09-10-2006, 16:18   #2 (permalink)
flashworker
 
Benutzerbild von brose
 
Registriert seit: Jun 2003
Beiträge: 199
Hast du irgendwo mal

PHP-Code:
my_xml.ignoreWhite true
gesetzt? Ansonsten kann es sein, das Leerzeichen und Tab als Node interpretiert werden.

Gruss
__________________
brose
brose ist offline   Mit Zitat antworten
Alt 09-10-2006, 17:23   #3 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
Ich würde mal wieder auf ein gutes altes Scope-Problem tippen ...
Bist du dir dessen bewusst, das die XML.onLoad-Methode im Kontext des XML-Objekts ausgeführt wird?
__________________
»Carpe diem«, sagte der Graf. (Terry Pratchett: Ruhig Blut!)
Janoscharlipp ist offline   Mit Zitat antworten
Alt 10-10-2006, 07:28   #4 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
Ja habe ich. Die XML wird folgendermaßen geladen. Hätte ich vielleicht gleich posten sollen. Vielleicht hilft das noch bei der Lokalisierung des Problems.

ActionScript:
  1. public function loadData(path:String):Void {
  2.     comments_xml = new XML();
  3.     comments_xml.ignoreWhite = true;
  4.     comments_xml.onLoad = onLoadXML;
  5.     comments_xml.load(path);
  6. }

EDIT: Ich habe gerade ein Problem entdeckt und behoben: Es fehlte ein / vor dem remark in der Markup. Das war es aber nicht. Ein trace gibt immer noch nix aus.

Geändert von compuboy1010 (10-10-2006 um 07:38 Uhr)
compuboy1010 ist offline   Mit Zitat antworten
Alt 10-10-2006, 09:29   #5 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
Nö, du bist einfach im falschen scope.
onLoadXML wird im Kontext vom comments_xml ausgeführt, nicht in dem deiner Klasse.
Such mal nach Delegate ...
__________________
»Carpe diem«, sagte der Graf. (Terry Pratchett: Ruhig Blut!)
Janoscharlipp ist offline   Mit Zitat antworten
Alt 10-10-2006, 09:34   #6 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
Have gerade mal ein trace("loaded: " + comments_xml.loaded); in die erste Zeile des onLoadXML handlers eingefügt und nun gibt er loaded: undefined aus.

Was ist da los?
compuboy1010 ist offline   Mit Zitat antworten
Alt 10-10-2006, 09:42   #7 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
Boah, das mit der Delegate Klasse raffe ich aber net.

Wie müsste das aussehen? So?

ActionScript:
  1. comments_xml.addEventListener("onLoad", Delegate.create(this, onLoadXML));
compuboy1010 ist offline   Mit Zitat antworten
Alt 10-10-2006, 09:43   #8 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
Klappt nicht:

Zitat:
There is no method with the name 'addEventListener'.
comments_xml.addEventListener("onLoad", Delegate.create(this, onLoadXML));
Wenn ich F1 richtig verstehe, dann kann man die Delegate Klasse nur auf Komponenten anwenden.


Geändert von compuboy1010 (10-10-2006 um 09:46 Uhr)
compuboy1010 ist offline   Mit Zitat antworten
Alt 10-10-2006, 09:49   #9 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
PHP-Code:
comments_xml.onLoad Delegate.create(thisonLoadXML); 
__________________
»Carpe diem«, sagte der Graf. (Terry Pratchett: Ruhig Blut!)
Janoscharlipp ist offline   Mit Zitat antworten
Alt 10-10-2006, 09:55   #10 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
Super!! Das klappt. Vielen Dank!
compuboy1010 ist offline   Mit Zitat antworten
Alt 10-10-2006, 09:58   #11 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
Aber ich verstehe immer noch nicht warum folgendes nicht gehen soll:

ActionScript:
  1. commentsXML.onLoad = slideshowModel.onLoadXML;

Ich "setzte" doch beide gleich!
compuboy1010 ist offline   Mit Zitat antworten
Alt 10-10-2006, 10:38   #12 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
Ein Beispiel dazu:
PHP-Code:
import mx.utils.Delegate;

o1 = new Object(); // das hier entspricht der Instanz deiner Klasse
o1.gaga "ich bin o1";
o1.blub = function() {
    
trace(this.gaga);
};

o2 = new Object(); // das hier entspricht dem XML
o2.gaga "ich bin o2";
o2.blub o1.blub;
o2.blub(); // ergibt "ich bin o2"
o2.blub2 Delegate.create(o1o1.blub);
o2.blub2(); // ergibt "ich bin o1" 
__________________
»Carpe diem«, sagte der Graf. (Terry Pratchett: Ruhig Blut!)
Janoscharlipp ist offline   Mit Zitat antworten
Alt 10-10-2006, 10:53   #13 (permalink)
... loves Japan!
 
Benutzerbild von compuboy1010
 
Registriert seit: Apr 2005
Ort: D'dorf; DE
Beiträge: 715
Ich lasse mir das mal durch den gehen.

Danke.
compuboy1010 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 14:02 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele