Here’s a simple class that wraps the URLLoader. I called this XMLLoader but it will load any text. The class itself illustrates the basic code required to load a text file. The class can be used to simplify the process in any project.

Save the following as XMLLoader.as

package {
	import flash.events.*;
	import flash.net.*;

	public class XMLLoader extends EventDispatcher {
		public var data;

		public function XMLLoader() {


		public function load( _xml_url:String ):void {
			var loader = new URLLoader();
			loader.addEventListener( Event.COMPLETE, on_complete );
			loader.load( new URLRequest( _xml_url ) );

		private function on_complete( e:Event ):void {
			data = e.target.data;
			dispatchEvent( new Event( Event.COMPLETE ) );

Use the class like this. Add the following code to any project:

my_xml = new XMLLoader();
my_xml.addEventListener( Event.COMPLETE, xml_loaded );
my_xml.load( "file.xml" );

Leave a Reply

Your email address will not be published. Required fields are marked *