Livi17
Livi17

Reputation: 1660

Get XMLvalue from root node in Flash AS3

My xml file looks like this.

<?xml version='1.0' encoding='iso-8859-1' ?>    
<template number='23' scroll='0'>
   <option id='audio' active='0' blockNext='0' forwardNext='0' url='media/'    cc='media/0000000_cc.xml'/>
   <option id='info' active='0' url='txt/p007info.txt'/>
   <option id='txtpop' active='0' url='txt/p007pop.txt'/>
</template>

In AS3, I'm trying to get the value "23" from the parameter "number" from the root "template" node.

I'm not even able to trace it.

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("xml/p030.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
    {
   myXML = new XML(e.target.data);

   trace(myXML);
   trace(myXML.template);

    }
}

It doesn't give me an error, but it doesn't show me anything either.

tracing this does not give me an error, but does not trace either.

trace(myXML.template.@number);

If I create a variable var number; and then make tha value of that variable equal to myXML.template.@number, and then trace the number variable, something is there, but it looks like an empty space.

number = myXML.template.@number; 
trace("number: "+ number)

If I trace any of the other values on the options nodes I have no problem seeing them.

Upvotes: 0

Views: 876

Answers (1)

ChickensDontClap
ChickensDontClap

Reputation: 2051

since template is the root node so you'd just need to reference it by:

number = myXML.@number;

Upvotes: 1

Related Questions