Skip to main content
Participant
August 3, 2006
Question

Undefined XML in Flash

  • August 3, 2006
  • 1 reply
  • 304 views
I'm trying to pull text out of an XML document into Flash 8. I've done this a million times, but for some reason it isn't working with this one. When I try access the data in a node, it comes back undefined. When I trace the "start" var, I get the following:
<?xml version="1.0" encoding="iso-8859-1"?><form2567><version0><page1><x1>test this one</x1><x2>test x2</x2></page1><page2 /></version0></form2567>
So I know Flash is getting to the XML doc and able to read it.

Here's my AS:
stop();
//
//LOAD XML DOC
//create new xml doc
var xmlDoc:XML;
//create new xml object
xmlDoc = new XML();
//ignore white space in xml doc
xmlDoc.ignoreWhite = true;
//ensure that xml doc loaded
xmlDoc.onLoad = function(success) {
if (success) {
trace(this);
} else {
trace("xml not loaded");
}
};
function test() {
var first = xmlDoc.firstChild.childNodes;
for (var i = 0; i<first.length; i++) {
start = first ;
trace("start = " + start);
}
}
//load the xml doc
xmlDoc.load("Form2567.xml");

currentXML = xmlDoc.firstChild.firstChild.firstChild.childNodes[0].firstChild.nodeValue;
pieceXML = currentXML;
trace ("currentXML = " + currentXML);
trace ("pieceXML = " + pieceXML);


Here's my XML:
<form2567>
<version0>
<page1>
<x1>test this one</x1>
<x2>test x2</x2>
</page1>
<page2>
</page2>
</version0>
</form2567>

Why do currentXML and pieceXML come back undefined?
This topic has been closed for replies.

1 reply

Inspiring
August 3, 2006
becasue your XML file is not loaded...

you have to put this :
currentXML = xmlDoc.firstChild.firstChild.firstChild.childNodes[0].firstChild.nodeValue;
pieceXML = currentXML;
trace ("currentXML = " + currentXML);
trace ("pieceXML = " + pieceXML);

into your onLoadInit function