Malfist
Malfist

Reputation: 31795

reading a url with flash

I have a flash applet that I want to grab a remote XML file and read it in as a string, how can I do this?

Upvotes: 0

Views: 152

Answers (1)

walpolea
walpolea

Reputation: 165

You can use a URLLoader to do this.

var url:String = 'http://www.myurl.com/myxml.xml';
var req:URLRequest = new URLRequest( url );

var urlloader:URLLoader = new URLLoader();
urlloader.addEventListener( Event.COMPLETE, XMLLoaded );

urlloader.load( req );

function XMLLoaded( e:Event ):void {

    trace( urlloader.data ); //urlloader.data is a String
    var xml:XML = XML( urlloader.data ); //create an AS3 XML object from the xml string

}

Upvotes: 2

Related Questions