This seems like it should be an easy one but I can't figure it out.
I'm trying out a very simple class that, when created, loads and XML file into the class's property. I must be getting a basic concept tangled up here because I can see the XML coming in just fine in the handleComplete function, but the class property _result remains empty.
What concept am I missing here?
Thanks in advance.
public class MyClass
{
private var _result;
public function MyClass()
{
var url:String = 'myFile.xml';
var loader:URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE, handleComplete );
loader.load( new URLRequest( url ) );
trace(_result); //returns nothing... didn't I just load it?
}
private function handleComplete( event:Event ) : void
{
try
{
var res:XML = new XML( event.target.data );
_result = res;
trace(_result); // this writes the myFile.xml to command line as I would expect.
}
catch ( e:TypeError )
{
// some error handling code
}
}
}
}