title: AS3 Returning a variable from an event listener function
body: <p>I'm trying to return XML from an event complete back to the main function, but can't figure out how to do it.</p>
  
  <p>Here's the functions I'm calling:</p>
  
  <p>Main File:</p>
  
  <pre><code>public var mySendAndLoad:SendAndLoad = new SendAndLoad(); 
  
  mySendAndLoad.sendData(url,variables)
  </code></pre>
  
  <p>The mySendAndLoad class:</p>
  
  <pre><code>package 
  {
  
      import flash.events.*;
      import flash.net.*;
      import flash.xml.XMLDocument;
  
      public class SendAndLoad
      {
          public var xml:XML = new XML();
          public var xmlList:XMLList;
  
          public function SendAndLoad()
          {
          }
          public function sendData(url:String, _vars:URLVariables):String
          {
              var request:URLRequest = new URLRequest(url);
              var loader:URLLoader = new URLLoader();
              loader.dataFormat = URLLoaderDataFormat.TEXT;
              request.data = _vars;
              request.method = URLRequestMethod.POST;
              loader.addEventListener(Event.COMPLETE, handleComplete);
              loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
              loader.load(request);
          }
          private function handleComplete(event:Event):String
          {
              var loader:URLLoader = URLLoader(event.target);
              xml = XML(loader.data);
              xmlList = xml.children();
              return(xmlList[1]);
          }
          private function onIOError(event:IOErrorEvent):void
          {
              trace("Error loading URL.");
          }
      }
  }
  </code></pre>
  
  <p>What I want to happen is have the xmlList come back to the main file. But since it isn't in the event I called (sendData) it doesn't get brought back.</p>
  
  <p>Any ideas?</p>