Variables in a class

Hi there,
I had tried searching this for the last 2 hours =[ so I decided to give in and ask.

I am have a number of variables defined in my document class and I have noticed that if I were to call a function in the same class to edit the value of the variable, the change would only apply to the scope of the function.

Now I hope I used scope in the right context there =D

Here is my code to show what I mean:


package {
    import flash.display.*;
    import flash.xml.*;
    import flash.events.*;
    import com.xml.xmlLoad;
    import com.gui.mainGui;

    public class main extends MovieClip {

        private var _targetURL:String = "Musicinfo.xml";
        private var getXMLLoad:xmlLoad;
        private var getGui:mainGui;
        public var xmlData:XML;
        public var _lessonInfo:XMLList;
 
        public function main() {
            loadXML(_targetURL);
            processXML();//This will return TypeError: Error #1009: 
                               //Cannot access a property or method of a null object reference.
                                //at main/::processXML()
            trace(xmlData);//This will also return an error similar to above

        }
        function loadXML(_targetURL) {
            getXMLLoad = new xmlLoad(_targetURL);
            getXMLLoad.addEventListener(Event.COMPLETE, onComplete);
        }
        function onComplete(evt:Event) {
            xmlData = getXMLLoad.getXML();
            trace(xmlData.fileInfo.blurb);//This traces the XML data
            trace(xmlData.fileInfo.author);//And so does this
        }
        function processXML() {
            trace(xmlData.fileInfo.blurb);//This dosen't =[
        }
    }
}

Could someone explain why this is?
This may be a AS2 understanding but I thought that if I at changed the value of a variable made in the class, then the value would be the new value for every time the variable was called after the new value was put there.

You can’t access the xmlData variable until you’ve instantiated the variable, or it’s null.

Problem is you call processXML before it’s loaded. You should call the function in the onComplete handler.

Ok I probably thought that by the time processXML(); was called the XML would be already loaded…

Does flash process in a liner way? I thought the functions would of been run in this order:

loadXML(); -> onComplete(); -> processXML();

Therefore I thought that the value of xmlData would then be the XML file when it came to do the processXML(); function.

no, it will start the processXML() immediately after loadXML() unless you specifically tell it to wait until the loadXML complete event dispatches.

How would I do that?

EDIT::
Well thinking about it could i just add an even listener?