XML.onLoad and other XML function questions

Goal: load XML data (it parses automatically), parse through the XML tree and assign the values to an array of my choosing for access later in the movie.

Problem: I can load the XML data, but the only time I can access the XML functions, i.e. XML.firstChild, or XML.getChildNodes(), is when I am within an XML.onLoad function.


var XMLdata:XML = new XML();
XMLdata.onLoad = function() {
trace(XMLdata.firstChild); // returns the first child

Shouldn’t I be able to call these XML function and properties from anywhere? not just within the XML.onLoad function? I look at other people’s scripts and they do it, but I can’t?

I created a function that parses through the data and puts it into an array. And that works well if I say
XMLdata.onLoad = my_array_funtion();

But the problem is, if I do it that way I can’t get the array out of the function. I can’t return the value because the function is being called from an onLoad event and the return value of the function isn’t assigned to a variable. So the array I create is worthless.

And there is no way to call the function, and have the XML.functions, i.e. XML.firstChild, to work outside of an XML.onLoad event. Is there? Please tell me there is a way.

In other attempts:
I tried assigning the array to a global variable, but evidently you can’t modify _globals within a function.

Ultimately, I need this array because later in the script I use the data on the fly, and I want instant access to it.

Any ideas?