title: Static method for XMLLoader class... how to return XML data after Event.COMPLETE function?
body: <p>I am attempting to build a generic XMLLoader class with a static <code>LOAD</code> method, with the intent to use it as follows...</p>
  
  <pre><code>private var _data:XML = XMLLoader.LOAD("path/to/xml_file.xml");
  </code></pre>
  
  <p>Then I could use it in any client and go-to-town with e4x. </p>
  
  <p>The general problem I am having is with the URLLoader's <code>COMPLETE</code> event, which necessarily calls a different function to set the XML data.
  This is preventing me from being able to return the XML from the <code>LOAD</code> method, since the data is being set <em>outside</em> that function. Obviously I need to wait for the <code>COMPLETE</code> event in order to make sure the data is available.</p>
  
  <p>I though, perhaps, I could create and return a <code>_waitForData</code> function, which recursively calls itself until the _data is set, then returns the data. But it seems redundant (since <code>Event.COMPLETE</code> is doing that anyway), and the way I tried it generates a stack overflow error.</p>
  
  <p>Heres what I tried:</p>
  
  <pre><code>public class XMLLoader {
  
      private static var _url:String = "";
      private static var _data:XML = null;
  
      public static function LOAD(url:String):XML {
  
          _url = url;
          var _xmlLoader:URLLoader = new URLLoader();
              _xmlLoader.addEventListener(Event.COMPLETE, _setData);
              _xmlLoader.load(new URLRequest(_url));
  
          return _waitForData();
      }
  
      static function _setData(e:Event):void {
          XML.ignoreWhitespace = true;
          _data = new XML(e.target.data);
      }
  
      static function _waitForData():XML {
  
          if( _data == null ) {
               _waitForData();
          }
  
          return _data;
      }
  
      public function LoadXML() {}
  
  }
  </code></pre>
  
  <p>I pretty new to the concept of recursive functions, so I have a feeling I implemented my _waitForData function incorrectly (if its even a good idea at all).</p>
  
  <p>I would appreciate any pointers on using static methods in this way, and whether what I am trying to do is possible...seems like a good idea I think.</p>