How do I assign a value to a property from within a method?

The question is exactly as the title of this thread states, how do I assign a value to a property from within a method? Before I go into detail, please take into consideration I’m new to actionscript 3.0 and its concept of object oriented programming. Actually I’m not that advanced with actionscript all together.

Basically I have two classes, “Main” and “XMLHandler”. The purpose of the class XMLHandler is to recieve the file path of an xml file and load it, and then to store the data from the xml file in a property ("_xml") within a class. Main is the document class for my main flash file. In Main I make a instance of XMLHandler and assign the file path via the constructor (I have no idea If I said that right).

This is the code from my XMLHandler class:

 
package com.handlers
{
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.events.ProgressEvent;
 import flash.net.URLLoader;
 import flash.net.URLRequest;
 
 public class XMLHandler extends Sprite
 {
 
  // PROPERTIES
 
  public var _xml:XML;
  public var _xmlURL:String;
  public var _xmlURLLoader:URLLoader;
  public var _xmlURLRequest:URLRequest;
 
  // CONSTRUCTOR
 
  public function XMLHandler(p_xmlURL:String):void
  {
   _xmlURL = p_xmlURL;
   xmlLoad();
  }
 
  // METHODS
 
  private function xmlLoad():void
  {
   _xmlURLRequest = new URLRequest(_xmlURL);
   _xmlURLLoader = new URLLoader();
   _xmlURLLoader.load(_xmlURLRequest);
   _xmlURLLoader.addEventListener(Event.COMPLETE, xmlLoaded);
  }
 
  private function xmlLoaded(e:Event):void
  {
   _xml = new XML(_xmlURLLoader.data);
   _xml.ignoreWhitespace = true;
  }
 }
}

And this is the code from my Main class:

 
package
{
 import com.handlers.XMLHandler;
 
 import flash.display.MovieClip;
 
 public class Main extends MovieClip
 {
 
  public function Main():void
  {
   var xmlH:XMLHandler = new XMLHandler("xml/items.xml");
   trace(xmlH._xml);
  }
 }
}

The problem is when I add the code “trace(xmlH._xml);” in Main to view the xml data of an instance of xmlHandler, it outputs “null”. From my understanding (which is limited), that means that the _xml property of XMLHandler wasnt assigned a value from the method xmlLoaded. In particular this line of code,

“_xml = new XML(_xmlURLLoader.data);”,

should assign the value from _xmlURLLoader to the property _xml. However if I edit that line like so,

“_xml = _xmlURLLoader.data;”,

it outputs the xml data from my xml file, but I also get:


null
TypeError: Error #1034: Type Coercion failed: cannot convert "<?xml version="1.0" encoding="utf-8"?>
<nav>
<nav_items>
<nav_item>
<image_url>images/image1.png</image_url>
<link_to>www.yahoo.com</link_to>
<sub_nav_items>
<sub_nav_item>
<image_url>images/image1.png</image_url>
<link_to>www.yahoo.com</link_to>
</sub_nav_item>
</sub_nav_items>
</nav_item>
 
<nav_item>
<image_url>images/image2.png</image_url>
<link_to>www.yahoo.com</link_to>
<sub_nav_items>
<sub_nav_item>
<image_url>images/image2.png</image_url>
<link_to>www.yahoo.com</link_to>
</sub_nav_item>
</sub_nav_items>
</nav_item>
 
<nav_item>
<image_url>images/image3.png</image_url>
<link_to>www.yahoo.com</link_to>
<sub_nav_items>
<sub_nav_item>
<image_url>images/image3.png</image_url>
<link_to>www.yahoo.com</link_to>
</sub_nav_item>
</sub_nav_items>
</nav_item>
 
</nav_items>
 
</nav>" to XML.
at com.handlers::XMLHandler/::xmlLoaded()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()

I would add more but this post is lengthy as it is. Anyway please help, and correct any incorrect terminology I used in the explaination of my problem. Apologies if none of this makes sense, if there are parts of my code where you dont understand what I was trying to do, I’ll try to explain it the best I can (if I can that is).