OOP problems

I’m trying to learn OOP but having some problems.

I have this class (just an example)


class MyClass
{	
	function loadCategories () : Array
	{
		// create a reference to this class instance to use within the XML onload handler
		var host = this;
		var parsedcategories:Array = new Array();
		var categories:XML = new XML ();
		categories.ignoreWhite = true;
		categories.onLoad = function (success : Boolean)
		{
			host.removeLoader ();
			if (success)
			{
				parsedCategories = host.parseCategories (this);
			}
		}
		categories.load ("test_categories.xml");
		return parsedCategories;
	}
	function parseCategories (categories_xml : XML):Array
	{
		var category_array : Array = new Array ();
		// do something
		// return category_array 
	}
}

Now when I call this like this:


var myClass:MyClass= new MyClass();
var categories:Array = myClass.loadCategories();
trace ("categories: " + categories);

then nothing is traced, because when the ‘return parsedCategories’ statement is executed the XML isn’t loaded yet.
What would be the best way to set up a class method that loads external data and returns it when loading is finished?

Cheers.