Skip to content
Dec 5 / Peter deHaan

Dynamically loading XML files in ActionScript 3.0

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();
}

One Comment

leave a comment
  1. ted / Feb 8 2009

    a clear example. thanks

Leave a Comment