Hi,
I'm new at actionscript 2.0, and I'd like to know how to read a xml attribute's value while iterating the xml.
So far, I can get the xml elements, but I can't get this issue to work.
Thanks in advance,
Brian
Hi,
I'm new at actionscript 2.0, and I'd like to know how to read a xml attribute's value while iterating the xml.
So far, I can get the xml elements, but I can't get this issue to work.
Thanks in advance,
Brian
Hum, need some code of yours to solve this mystery ;p Otherwise you will get some boring links to the sdk documentation. But ill give it a shot, it's AS3 code and I don't know if xml had some major rework from AS2->AS3. Must say its a very nice experience to work with xml in AS3 though.
//current level number
public var mCurrentLevelNumber:Number = 0;
//read from file variables:
private var mLoader:URLLoader = new URLLoader();
private var mXML:XML;
//add a listener
mLoader.addEventListener(Event.COMPLETE, OnLoadXML, false, 0, true);
mLoader.load(new URLRequest("../assets/content.xml"));
....
/*
OnLoadXML
Parses the data from the file, loads one level
@e:Event
*/
private function OnLoadXML(e:Event):void{
var loadLevel:Array = new Array();
try{
//convert the text into an XML
mXML = new XML(e.target.data);
//trace("reading from .xml is done, values: ", mXML);
trace(" Name of the level: ", mXML.level[mCurrentLevelNumber].title.text() );
for (var j:int=0; j<mXML.level[mCurrentLevelNumber].tiles.tilerow.length(); j++) {
trace("Row",j,", tiles:", mXML.level[mCurrentLevelNumber].tiles.tilerow[j].text() );
}
//......
//}
}catch (e:TypeError){
trace("Could not parse the XML");
trace(e.message);
}
}
And the xml file structure;
<!-- pretty level arrays... -->
<levels>
<level>
<title>Level 1</title>
<tiles>
<tilerow>1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 1 1 1 3 1 13</tilerow>
<tilerow>1 0 0 0 0 0 0 0 0 0 0 0 10 12 0 9 0 0 0 0 0 0 0 0 1</tilerow>
<tilerow>1 0 0 0 0 1 0 0 0 0 0 0 10 11 11 11 12 0 6 1 0 0 0 0 1</tilerow>
<tilerow>1 9 1 0 0 1 0 0 0 0 0 0 10 12 0 9 0 0 6 0 0 0 0 0 1</tilerow>
</tiles>
</level>
</levels>
hi there ...
well, any element node has the property attributes
... this is simply an anonymous objects stuffed with the info ...
just do someXML.attributes.someAttribute
and you will get the desired value ...
likewise, you may check out this little library i made for AS2, to bring parts of e4x to the AS2 and simplify XML processing ... it is not at all production level though!