Monday, May 5, 2008

AS3 basic XML use

// we use URLLoader instead of XML.load();
var loader:URLLoader = new URLLoader();

loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("example.xml"));

function loadXML(myEvent:Event):void {
        var xml:XML = new XML(;
                // you can now traverse the xml object using the actual tag names
                // you can also target all tags of a certain name
                // with the .. "descendent accessor"

                // and we use the @ accessor for attributes

// here is some xml for your example.xml file


<?xml version="1.0" encoding="UTF-8" ?>
<anothertagname myattribute="my attribute goes here">my text goes here</anothertagname>


No comments: