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::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<= 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";
}
}
}