# After loading an xml file, get Error 1009 while trying to access it later

**URL:** <https://forum.kirupa.com/t/after-loading-an-xml-file-get-error-1009-while-trying-to-access-it-later/248633>\
**Category:** flash\
**Created:** [January 10, 2008, 9:22am UTC](https://forum.kirupa.com/t/after-loading-an-xml-file-get-error-1009-while-trying-to-access-it-later/248633 "2008-01-10T09:22:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cauchy](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@cauchy](https://forum.kirupa.com/u/cauchy)\
**Post date:** [January 10, 2008, 9:22am UTC](https://forum.kirupa.com/t/after-loading-an-xml-file-get-error-1009-while-trying-to-access-it-later/248633/1 "2008-01-10T09:22:52Z")

</div>

The error I get is:

null  
TypeError: Error #1009: Cannot access a property or method of a null object reference.

Trace #1 confirms that the xml file was loaded successfully by loadXml(), but when I access the file in the timeline using the getStatus() method the object is null (trace #2).

Is there an obvious solution to this? Class code below…

package  
{  
import flash.display.Sprite;  
import flash.events.Event;  
import flash.events.IOErrorEvent;  
import flash.net.URLLoader;  
import flash.net.URLRequest;

```
public class readXml extends Sprite
{		
	public var xmlFile:XML;	
	private var urlLoader:URLLoader;
	
	public function readXml() 
	{
		
	}
	
	public function loadXml(xmlInputFileName:String):void 
	{
		urlLoader = new URLLoader();
		var myURLRequest:URLRequest = new URLRequest(xmlInputFileName);
		
		urlLoader.load(myURLRequest);
		urlLoader.addEventListener(Event.COMPLETE, completeListener); 
		urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorListener);
	}
	
	private function completeListener(e:Event):void 
	{
		xmlFile = new XML(urlLoader.data);
		trace(xmlFile.toString()); // Trace #1
	}

	private function ioErrorListener(e:Event):void 
	{
		trace("IO Error for XML data loading");
	}
		
	public function getStatus():void
	{
		trace(xmlFile.toString()); // trace #2
	}		
}

```

}

The timeline code is:

function createAndLoadXmlObject(xmlFile:String):readXml {  
var xmlObject:readXml = new readXml();  
xmlObject.loadXml(xmlFile);  
return xmlObject;  
}

var xmlExamObject:readXml = createAndLoadXmlObject(“myfile.xml”);  
addChild(xmlExamObject);

xmlExamObject.getStatus();
