# Load XML class

**URL:** <https://forum.kirupa.com/t/load-xml-class/296040>\
**Category:** Uncategorized\
**Created:** [September 8, 2009, 11:39pm UTC](https://forum.kirupa.com/t/load-xml-class/296040 "2009-09-08T23:39:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phed](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@phed](https://forum.kirupa.com/u/phed)\
**Post date:** [September 8, 2009, 11:39pm UTC](https://forum.kirupa.com/t/load-xml-class/296040/1 "2009-09-08T23:39:25Z")

</div>

Hi,

I am new to trying to put things into classes and am having trouble at a kind of basic level:  
I have a class that will read an xml file and then load the xml into a public variable like this:

```auto
package
{
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.display.Sprite;
	
	public class LoadXML extends Sprite
	{
		public var myXml:XML;
		private var urlLoader:URLLoader=new URLLoader();
		private var myUrl:String;
		public function LoadXML(url:String)
		{
			myUrl = url;
			init();
		}
		private function init():void
		{
			urlLoader.addEventListener(Event.COMPLETE, onXMLLoaded);
			urlLoader.load(new URLRequest(myUrl));
		}
		private function onXMLLoaded(e:Event):void
		{
			myXml = new XML(e.target.data);
		}
	}
}

```

when I create an instance of this class from within another class like this:

```auto
xmlLoad:LoadXML = new LoadXML("test.xml");

```

the xml loads and I can trace it out from within the LoadXML class but when I try to access it from the class where I created the instance like this:

```auto
trace(xmlLoad.myXml);

```

it just returns “null”.

I’d appreciate any help - thanks!
