0 Replies Latest reply on Sep 3, 2008 12:45 PM by loretz

    Flex/Actionscript External XML Scope Issue

    loretz
      I am processing an external XML file in an event listener after the URLLoader is complete. The issue I'm having is that I want getProduct() to return the XML data. How can I get the data from the event listener getXML(). I tried creating a public variable outside of the functions but I can't access it from within the two functions.

      package messages
      {
      import flash.events.Event;
      import flash.net.*;

      //Returns the current product
      public class FetchXMLData
      {
      public static function getXML(e:Event):void {

      var myProduct:XML = new XML(e.target.data);
      trace(myProduct.product);
      }

      public static function getProduct():XML{

      var loader:URLLoader = new URLLoader();
      loader.addEventListener(Event.COMPLETE, FetchXMLData.getXML);
      loader.load(new URLRequest(" http://www.example.com/api"));

      var myProducts:XML = new XML();
      //get the value from the listener?!
      return myProducts;
      }
      }
      }