Custom XML loader class

Hi!

I’ve been making the transition from AS2 to AS3. I hadn’t dealt with classes before I started with AS3, so I’ve been running into a few snags. My current problem is an XML loading class that I’m trying to put together. It worked fine when coded in the main timeline, but now that I have my XML object in a class, I don’t know how to access it in my main swf.

package {
    import flash.events.*;
    import flash.net.*;
    import flash.xml.*;

    public class XmlParser {
        // Creating a loader variable
        private var loader:URLLoader = new URLLoader();
        // Our XML object to be loaded
        public var mainNavXML:XML;

        public function XmlParser() {
            parser();
        }
        private function parser():void {
            // A listener to react after the xml has been loaded
            loader.addEventListener(Event.COMPLETE, onLoaded);
            //loading in our xml
            loader.load(new URLRequest("sitemap.xml"));
        }
        // Our reaction function
        private function onLoaded(e:Event):void {
            // Takes the xml data we loaded and parses its data
            mainNavXML = new XML(e.target.data);
            //trace(mainNavXML);
        }
    }
}

when I trace out the variable, “mainNavXML,” in the class, I get my xml:

Yet, when I try to trace my XmlParser.mainNavXML variable from the main timeline I get a "null." Here is the code in the first frame of my actions layer of the main swf. The main swf and my class are in the same directory; so therefore I don't have to import the class, just call a new instance of it, right?
var test:XmlParser = new XmlParser();
trace(test.mainNavXML);

How would I access the XML object’s contents from my XmlPars Class?

Some have suggested that my main swf trace is executing before my XmlParser class loads the xml. To fix it we need to put in some event listeners? What would be the best way to do this? I already have a " oader.addEventListener(Event.COMPLETE, onLoaded);"

I hope this didn’t take up too much of anyone’s time, and that its a simple thing.

Thanks for your help! =)