Translator
Categories
Archives

Load XML in Flash (AS3)

XML is the most popular data delivery methods for Flash and Flex. It’s fairly simple to load and consume XML, but it’s a little intimidating if you’re a ActionScript noob. Use the following code to pull in xml data and display it via a Flash trace.

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, getXML);
// Request XML File from URL
loader.load(new URLRequest("http://www.noobflash.com/feed/"));

function getXML(event:Event):void {
	var xmlData:XML = new XML(event.target.data);
	trace(xmlData);
}

Once you have the XML loaded, you will need to parse the XML using E4X. (Read: Parse XML Data in ActionScript 3 Using E4X)

2 Responses to “Load XML in Flash (AS3)”

  • [...] E4X is a programming language extension that adds native XML support to ActionScript. This means that once you have some XML data loaded into Flash, you can reference and traverse that data by using E4X. For our example let’s assume that the XML below is what you have loaded into Flash. I’m assuming you already have a XML object assigned to a variable, but in this example I’m creating animalXML XML object. (Read: Load XML Using AS3) [...]

  • Nal:

    I have been looking and looking for a simple piece of code, some sort of Event Listener or function, that would load a particular node/element from my xml document into a Movie Clip that is a Dynamic Text field in Flash using AS3.

    in other words, after I’ve loaded the xml, how do I get the appropriate text into the text field?

Leave a Reply