You can use the URLLoader
class to load external data from a URL. The URLLoader
class downloads data from a URL as text or binary data. In this section, we will see how to use the URLLoader
class for loading external XML data into your application. You can create a URLLoader
class instance and call the load()
method by passing URLRequest
as a parameter and register for its complete event to handle loaded data. The following code snippet shows how exactly this works:
private var xmlUrl:String = "http://www.foo.com/rssdata.xml"; private var request:URLRequest = new URLRequest(xmlUrl); private var loader:URLLoader = new URLLoader(; private var rssData:XML; loader.addEventListener(Event.COMPLETE, completeHandler); loader.load(request); private function completeHandler(event:Event):void { rssData = XML(loader.data); trace(rssData); }
Let's see one quick complete sample of loading RSS data from the Internet:
<?xml version="1.0" encoding="utf-8"?> <mx:Application...