Hello I keep running into errors and outputs that say “undefined” in my output panel when I try and parse XML using AS3. I would like to get the values of score1, score2….
Can anyone tell me what I am doing wrong?
thanks
Scientific
////AS3//////////
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
var myXML:XML;
var xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(new URLRequest("scores.xml"));
function xmlLoaded(e:Event):void
{
myXML = new XML(e.target.data);
trace(myXML.scores1);
}
//////xml file////////////
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<root>
<scores>
<id>1</id>
<score1>105</score1>
<score2>60</score2>
<score3>56</score3>
<score4>48</score4>
<score5>30</score5>
</scores>
</root>
</feed>
You might find the descendant accessor .. useful. Example:
Edit:
There is something about using the generic namespace that is causing some problems. Adding an alias fixes it, eg:
Otherwise Flash is expecting that you are going to use fully qualified names to specify the element you are trying to access: