PDA

View Full Version : Cannot get XML data to load


adover
04-04-2008, 09:30 AM
Sorry if this is on the wrong board! I'm wanting to load XML data into my flash animation but it just doesnt seem to be working! :( here is my code, hopefully someone can point me in the right direction!

//XML

matData_xml = new XML();
matData_xml.ignoreWhite=true;
matData_xml.load('data.xml');
matData_xml.onLoad=function(success){


if (success){
trace("loaded");
}else{
trace('flopped');
}
}

function loadXML(loaded) {
if (loaded) {
var xnRootNode:XMLNode=this;
_root.mainContent.maintitle.text = xnRootNode.firstChild.childNodes[3].childNodes[0].firstChild.nodeValue;
trace(xnRootNode.firstChild.childNodes[3].childNodes[0].firstChild.nodeValue);

}
}
as u can see, maintitle is the textfield I want to populate with the xml data, and its not working, the trace which follows does not work either!

any help appreciated :)

Durnus
04-04-2008, 06:42 PM
Yep, wrong board. This should go on the AS2 forum.

Do *NOT,* repeat, do *NOT* make a new thread there, unless you delete this one.

My only suggestions are to: tell us what it does do, or if it does not do anything at all, tell us that. Second, is the function loadXML supposed to go? If so, then you need:

var matData_xml = new XML(); //You might want to declare your variable...
matData_xml.ignoreWhite=true;
matData_xml.load('data.xml');
matData_xml.onLoad = loadXML;

function loadXML(loaded) {
trace("Okay, I should be loaded now...");
if (loaded) {
var xnRootNode:XMLNode=this;
_root.mainContent.maintitle.text = xnRootNode.firstChild.childNodes[3].childNodes[0].firstChild.nodeValue;
trace(xnRootNode.firstChild.childNodes[3].childNodes[0].firstChild.nodeValue);

}
}


EDIT: Argh, sorry, just read the second to last line in your post. Well, try doing it my way and see if it works for you. It could be possible the function() thing isn't working... don't know why it wouldn't be though.

EDIT2: Oh, you could be set to AS3 mode... you can either create a new file using AS2 from the start, or change it in your actionscript settings in the Public settings dialog.