# Sometimes, loading xml gives a "undefined" message?

**URL:** <https://forum.kirupa.com/t/sometimes-loading-xml-gives-a-undefined-message/326961>\
**Category:** flash\
**Created:** [January 26, 2012, 11:04am UTC](https://forum.kirupa.com/t/sometimes-loading-xml-gives-a-undefined-message/326961 "2012-01-26T11:04:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![keitai](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@keitai](https://forum.kirupa.com/u/keitai)\
**Post date:** [January 26, 2012, 11:04am UTC](https://forum.kirupa.com/t/sometimes-loading-xml-gives-a-undefined-message/326961/1 "2012-01-26T11:04:38Z")

</div>

Hi,

Been a while and i have AS2 file which loads a .xml file. It works but not all the time. Without changing anything just refreshing the browser i get a undefined in the textfields. How can i make sure the xml is loaded?

I use the following AS

```auto

var xmlPath:String = "/quotes.xml";
var xml:XML = new XML();
xml.ignoreWhite = true;

xml.onLoad = function(success) {
	if (success) {
			var nodes= this.firstChild.firstChild.childNodes;
			numOfItems = nodes.length;
			
			for(i=0;i<numOfItems;i++) {
				var item = nodes*;
				quotes.push(nodes*.firstChild.childNodes);
				authors.push(item.lastChild.childNodes);
			}
	} else {
		gotoandplay(10);
	}
}
//xml.load(xmlPath+"?nocache="+getTimer());
xml.load(xmlPath);

```

and on frame 10 i have the follow init function to get a random quote

```auto
function init(){
	//random number
	var randomSelection = Math.floor((Math.random() * myQuotes.length));
	var quote = myQuotes[randomSelection];
	var auth = myAuthors[randomSelection];
	trace(randomSelection);
	showQuote(quote,auth);
	myQuotes.splice(randomSelection, 1);
	if(myQuotes.length == 0) {
		myQuotes = quotes.slice();
	}
	myAuthors.splice(randomSelection, 1);
	if(myAuthors.length == 0) {
		myAuthors = authors.slice();
	}
}

```
