Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 07-02-2006, 23:41   #1 (permalink)
Neuer User
 
Registriert seit: Jun 2001
Ort: Germany - Bayern
Beiträge: 147
XML Daten mit Funktion auslesen und abspeichern

Hi Leute,

irgendwie haeng ich gerade fest.
Ich habe eine externe .as File in der ich den Inhalt von XML Dateien mittels Funktionen auslese und dann speichern moechte:

PHP-Code:
//Set up content
xmlContent = new Array();
xmlContent getContent();

//Build menu
createTitle(xmlContent["title"]);
createItems(xmlContent["items"]);


function 
getContent() {
    
contentArray = new Array();
    
topMenuItems = new Array();
    
myXML = new XML();
    
myXML.ignoreWhite true;
    
myXML.load("../xml/topmenu.xml");
    
myXML.onLoad = function (success) {
        if(
success) {
            
rootNode myXML.firstChild;
            
//Create menu title
            
contentArray["title"] = rootNode.attributes.name;
            
subnodes rootNode.childNodes;
            for (
m in subnodes) {
                
currentNode subnodes[m];
                
index topMenuItems.length;
                
//Save all Items in a 3 dimensional Array
                
topMenuItems[index] = new Array();
                
topMenuItems[index]["name"] = currentNode.attributes.name;
                
topMenuItems[index]["subitems"] = new Array();
                
//Save all subItems in 3rd dimension
                
subItems currentNode.childNodes;
                for (
n in subItems) {
                    
currentSub subItems[n];
                    
subIndex topMenuItems[index]["subitems"].length;
                    
topMenuItems[index]["subitems"][subIndex] = new Array();
                    
topMenuItems[index]["subitems"][subIndex]["subName"] = currentSub.attributes.name;
                    
topMenuItems[index]["subitems"][subIndex]["path"] = currentSub.attributes.path;
                }
            }
        }
    }
    
trace (contentArray["title"]);
    
contentArray["items"] = new Array();
    
contentArray["items"] = topMenuItems;
    return 
contentArray;

Das Problem ist, dass xmlContent nie das Array bekommt.
Mit trace habe ich gesehen, dass contentArray nur in der onLoad function die richtigen Werte hat. Sobald die onLoad function jedoch beendet ist verliert die Variable ihre Gueltigkeit. Da onLoad ja ein Event ist kann ich ja hier auch nicht mit return arbeiten.

Im Grunde will ich ganz einfach nur eine Funktion die mir den Inhalt ausliesst, in meiner Hauptleiste speichert. Habs auch schon mit Objekten und Methoden probiert die ich innerhalb der Funktion aufrufe, aber immer das gleiche. Sobald die Funktion die den Inhalt holst (onLoad) beendet ist, ist alles weg.

Waere super wenn jemand ne idee haette!

Danke
__________________
[stmole].[ http://www.stmole.de ]
stmole ist offline   Mit Zitat antworten
Alt 08-02-2006, 08:13   #2 (permalink)
_//\\#//\\_
 
Benutzerbild von warrantmaster
 
Registriert seit: Jan 2003
Beiträge: 7.060
du mußt schon auf das onload warten, wenn du auf vars aus diesem event zurückgreifen willst.

PHP-Code:
laber ()

function 
los(arr)
{
    
trace (arr)
}

function 
laber ()
{
    var 
arr=[]
    var 
= new XML ()
    
m.ignoreWhite true
    m
.onLoad = function(ok)
    {
        if(
ok)
        {
            for(var 
i=0;i<this.firstChild.childNodes.length;i++)
            {
                
arr.push(this.firstChild.childNodes[i].firstChild)
            }
            
los(arr)
        }
    }
    
m.load('test.xml')


Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
	<item>hallo</item>
	<item>welt</item>
</root>
warrantmaster 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 13:53 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele