Dynamically loading XML files in ActionScript 3.0

by Peter deHaan on December 5, 2008

in URLLoader, XML

The following example shows how you can load a remote XML document in ActionScript 3.0 using the URLLoader class.

Full code after the jump.

// ActionScript 3.0
/**
 * Requires:
 *   - TextArea control in the Library.
 */
import fl.controls.TextArea;
 
var xml:XML;
 
var urlRequest:URLRequest = new URLRequest("http://www.helpexamples.com/crossdomain.xml");
 
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.load(urlRequest);
 
var textArea:TextArea = new TextArea();
textArea.move(5, 5);
textArea.setSize(stage.stageWidth - 10, stage.stageHeight - 10);
addChild(textArea);
 
function urlLoader_complete(evt:Event):void {
    xml = new XML(evt.currentTarget.data);
    textArea.text = xml.toXMLString();
}

{ 1 comment… read it below or add one }

1 ted 02.08.09 at 3:54 pm

a clear example. thanks

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: