actionscript-misc-LoadXML.ax [swf] flex
package { import flash.display.*; import flash.events.*; import flash.net.*; // Demonstrates the code required to load external XML public class @ax-actionscript-misc-LoadXML extends Sprite { // The property that will eventually contain the loaded XML private var novel:XML; // The object used to load the XML private var urlLoader:URLLoader; // Constructor public function @ax-actionscript-misc-LoadXML () { // Specify the location of the external XML var urlRequest:URLRequest = new URLRequest("novel.xml"); // Create an object that can load external text data urlLoader = new URLLoader(); // Register to be notified when the XML finishes loading urlLoader.addEventListener(Event.COMPLETE, completeListener); // Load the XML urlLoader.load(urlRequest); } // Method invoked automatically when the XML finishes loading private function completeListener(e:Event):void { // The string containing the loaded XML is stored in the URLLoader // object's data property (urlLoader.data). To create a new XML // instance from that loaded string, we pass it to the XML constructor novel = new XML(urlLoader.data); trace(novel.toXMLString()); // Display the loaded XML, now converted // to an XML object } } }
(C) Æliens 27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.