PDA

View Full Version : Accesing XML vars


qrosity
03-03-2008, 05:33 PM
I have an XML that looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<thedata>
<events name="birthday" action="sing" message="sit amet turpis." />
<events name="wedding" action="party" message="sit amet turpis." />
<events name="funeral" action="cry" message="sit amet turpis." />
<customer ref="10" name="John" city="London" quotation="sit amet turpis." />
<customer ref="11" name="Mary" city="Madrid" quotation="Nulla scelerisque nunc eget sem. Quisque a eros vel nisl aliquet tempor." />
<customer ref="12" name="Sam" city="Lisboa" quotation="Nunc sed elit eget lacus venenatis sagittis. Vivamus scelerisque mollis nulla. Nam non purus id dui ullamcorper iaculis." />
</thedata>

I'm trying to access some parts of the info, but I allways get an undefined message.
This is how my code in flash looks like.
It is also possible to change XML file, but I would like to keep it all together, not to split it in different XML files, but jus one.

var x:XML = new XML();
x.ignoreWhite = true;
x.onLoad = function(exito) {
var events:Array = new Array();
if (exito) {
events = this.firstChild.childNodes;
var customers:Number = 0;
for ( i=0; i<events.length; i++ ) {
if (events[i].customer != undefined ) {
customers++;
}
}
trace("vars are ok");
} else {
trace("Haven-t found vars");
cuerpo_txt.text = "Error";
}
};
function loadTheVarsXML() {
x.load("prueba3.xml");
}