How to load data from a remote URL?

I found that the DataLoadingTest class given in Adobe Labs ActionScript 3 Resources site was buggy and did not work. I’ve corrected the file myself and made it work. Here is the working code 🙂

package
{
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
public class DataLoadingTest
{
private var urlString : String = "http://weblogs.macromedia.com/mxna/";
private var dataLoader : URLLoader;
public function DataLoadingTest ()
{
dataLoader = new URLLoader ();
dataLoader.addEventListener ("complete", onDataLoad);
dataLoader.addEventListener ("securityError", onSecurityError);
dataLoader.load (new URLRequest (urlString));
}
private function onDataLoad (event : Event) : void
{
trace ("Raw Data : " + event.target.data);
}
private function onSecurityError (event : Event) : void
{
trace ("Security Error : " + event);
}
}
}
/*
//Usage:-
//place the following code in the first frame
var dlt:DataLoadingTest=new DataLoadingTest();
*/

package
{
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
public class DataLoadingTest
{
private var urlString : String = "http://weblogs.macromedia.com/mxna/";
private var dataLoader : URLLoader;
public function DataLoadingTest ()
{
dataLoader = new URLLoader ();
dataLoader.addEventListener ("complete", onDataLoad);
dataLoader.addEventListener ("securityError", onSecurityError);
dataLoader.load (new URLRequest (urlString));
}
private function onDataLoad (event : Event) : void
{
trace ("Raw Data : " + event.target.data);
}
private function onSecurityError (event : Event) : void
{
trace ("Security Error : " + event);
}
}
}
/*
//Usage:-
//place the following code in the first frame
var dlt:DataLoadingTest=new DataLoadingTest();
*/

 

You can download the file from here.

Leave a Reply