I created an XML file named “stage1.txt” in the folder “musics”.
The XML File is :
<music>
<speed>10</speed>
<time>
<note>1</note>
<note>12</note>
<note>32</note>
<note>41</note>
</time>
<where>
<lane>3</lane>
<lane>2</lane>
<lane>1</lane>
<lane>4</lane>
</where>
</music>
And then in the flash file I used the following code to recall the XML file :
and then in the flash file I used the following code to get the data.
var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("musics/stage"+_global.stages+".xml");
var temp = 0, temp2 = 0;
myXML.onLoad = function(success){
if (success){
trace (myXML);
}
}
It worked fine until here. However, I wanted to recall the first value of the XML file, the “speed”.
I tried using this code :
var speed = myXML.firstChild.firstChild.nodeValue;
but it doesn’t seem to work.
Tried other things like :
myXML.firstChild.childNodes[0].nodeValue
but doesn’t work too.
Add an extra firstChild in there. I’m not really sure why, but it seems the parser handles the document as a whole as being a seperate level.
The best way to find the stuff you need when things aren’t working out is to trace and see what it contains. So start with the xml object (‘trace(myXML)’) and traverse from there on ‘trace(myXML.firstChild)’ -> ‘trace(myXML.firstChild.firstChild)’ -> etc. until you find the info you need.