Flash AS3 ( actionscript 3 ) Loading or Reading external XML documents
Here is a sample of how to use Flash AS3 (aka ActionScript 3 ) to Load or Read external XML documents. Flash’s ability to read XML files, in my opinion, makes it one of the most valuable resources available. So, lets tap into this resource and see what is new and different with AS3.
Lets start by using a new AS3 class called the URLLoader class to load the XML data from a URL. We used this same URLLoader class in the getURL sample.
Here is some AS3 ActionScript:
var myXML:XML = new XML();
var XML_URL:String = “http://www.smithmediafusion.com/mytest.xml”;
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(“complete”, xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
trace(“Data loaded.”);
}
You’ll see that again everything is oriented to a object or a function. This makes it easy if we need to call the same function again at some point down the time line.
This pointer from the Flash AS3 help:
/*
You can also use the XMLSocket class to set up an asynchronous XML socket connection with a server. For more information, see the ActionScript 3.0 Language and Components Reference.
*/
Posted in: Flash Gen., Flash Helps | Comments(2)
February 12th, 2008 at 11:00 am
[...] that combines a couple things that I’ve posted in the past, including the for loop and xml loading. So we use those methods in this FLV Video playlist sample. Since the xml file is in RSS 2.0 type [...]
February 18th, 2008 at 4:34 pm
[...] Podcast player. This little sample uses similar Flash AS3 methods in past posts like the for loop, xml loading, and the Flash AS3 Video [...]