The subject of loading data from servers is much more involved than can be covered in a chapter on XML. Therefore, we discuss this in its own section later on in the book. However, 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
import flash.net.*;
var myXML:XML;
var url:URLRequest = new URLRequest(“http://www.your-domain.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);
}
}
April 21, 2009
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment