Question
Loading XML in AS3
OK, so I think I have the basics of loading XML in AS3. But I
can't seem to access the info once it is loaded. I'm using the to
load the .xml file:
var myXML:XML = new XML();
var XML_URL:String = "music.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
trace("Data loaded.");
}
But when I go to trace the .xml file with this:
trace(myXML.toXMLString());
I get nothing. However, if I place this trace inside the xmlLoaded function it traces it out. My problem is I want access to the info outside of that function. What am I doing wrong? Any advice or help would be greatly appreciated. Thanks.
var myXML:XML = new XML();
var XML_URL:String = "music.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
trace("Data loaded.");
}
But when I go to trace the .xml file with this:
trace(myXML.toXMLString());
I get nothing. However, if I place this trace inside the xmlLoaded function it traces it out. My problem is I want access to the info outside of that function. What am I doing wrong? Any advice or help would be greatly appreciated. Thanks.