# Error 1009. help! :S

**URL:** <https://forum.kirupa.com/t/error-1009-help-s/283865>\
**Category:** Uncategorized\
**Created:** [March 11, 2009, 11:07pm UTC](https://forum.kirupa.com/t/error-1009-help-s/283865 "2009-03-11T23:07:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beaulne](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/beaulne/32/3027_2.png) [@Beaulne](https://forum.kirupa.com/u/Beaulne)\
**Post date:** [March 11, 2009, 11:07pm UTC](https://forum.kirupa.com/t/error-1009-help-s/283865/1 "2009-03-11T23:07:11Z")

</div>

Ok, so when I run my program it boots up alright. When I go to run a function called onComplete AND it executes in a specific way (the if statment is correct) so that it Jumps to the next frame, I get the error.

> TypeError: Error #1009: Cannot access a property or method of a null object reference.  
> at MethodInfo-1()  
> at flash.events::EventDispatcher/dispatchEventFunction()  
> at flash.events::EventDispatcher/dispatchEvent()  
> at [flash.net](http://flash.net)::URLLoader/onComplete()  
> I believe its because the event has not finished completing… Is there any way around this?

My Code

> stop();  
> //Define The Key word that is in the input box on load.  
> stage1.country\_box.country\_txt.text=“Country Name”;

//Setup the submit button as a button and its event listener  
stage1.submit\_btn.buttonMode=true;  
stage1.submit\_btn.addEventListener(MouseEvent.CLICK, submit);

//the buttons function handler  
function submit(e:MouseEvent) {  
//Loads the XML  
var xmlLoader:URLLoader = new URLLoader();  
xmlLoader.addEventListener(Event.COMPLETE, onComplete);  
xmlLoader.load(new URLRequest(“store.xml”));

```
function onComplete(evt:Event):void {

    var xmlData:XML=new XML(evt.target.data);
    var bookTitles:XMLList=xmlData.country.namez.text();

    // loop that scans the XML file
    for (var n = 0; n&lt;= bookTitles.length(); n++) {
        if (bookTitles[n]==stage1.country_box.country_txt.text.toUpperCase()) {
            stage1.submit_btn.removeEventListener(MouseEvent.CLICK, submit);
            xmlLoader.removeEventListener(Event.COMPLETE, onComplete);
            gotoAndPlay(2);
        }
        incorrect.text="Incorrect Country";
    }

}

```

}
