The subject of loading data from servers is much more involved than can be covered on XML. in case you’re
really itching to try loading some data from a server, these are the basics of how it’s done.
In the AS2 implementation of XML, the data was loaded through a method called by the XML
class. However, in AS3, that functionality has been moved outside of the class to the flash.net
package. In this example we use a URLLoader to load the XML file and then create an XML object
from the data we’ve loaded.
{code}
import flash.net.*;
var myXML:XML;
var url:URLRequest = new URLRequest(“http://www.sptechnolab.com/test.xml”);
var loader:URLLoader = new URLLoader(url);
loader.addEventListener(Event.COMPLETE, onLoadComplete);
function onLoadComplete(event:Event):void {
if (loader.data) {
myXML = XML(loader.data);
}
}
{/code}
import flash.net.*;
var myXML:XML;
var url:URLRequest = new URLRequest(“http://www.sptechnolab.com/test.xml”);
var loader:URLLoader = new URLLoader(url);
loader.addEventListener(Event.COMPLETE, onLoadComplete);
function onLoadComplete(event:Event):void {
if (loader.data) {
myXML = XML(loader.data);
}
}
{/code}
You can replace the URL in this example with the location of your data. When the loader is done
loading, the onLoadComplete() function is called, which converts the data loaded by the loader
into XML form. From this point, you can use myXML the same way we’ve used the other XML data.
Manage & Developed By Sptechnolab.com