0 Replies Latest reply on Jun 3, 2007 2:38 PM by raffjones

    How can one return a value from a public static function in AS3

      I used to use code of the following nature quite a lot:

      // in some class, use a public static function in a "DataManager" class to load XML, parse it, and return the result to a function in the class that called it

      // function "doSomething" in this class
      var menuData:Object = DataManager.loadXML("path/to/xml", this, doSomething);

      in the DataManager class I would have a public static function as follows:

      public static function loadData(xml_url:String, obj:Object, func:Function) {
      var menu_xml:XML = new XML();
      menu_xml.ignoreWhite = true;
      var dm:DataManager = new DataManager();
      menu_xml.onLoad = function(ok) {
      if (ok) {
      var menuObject:Object = dm.parseMenuData(this);
      func.call(obj, menuObject);

      I've omitted the actual XML Parsing code, as its not really relevant

      As you can see, I would call the public static method and get a processed result back in the form of a single Object.

      My question is, using ActionScript 3.0, I can't see a way to do this using the Event class - of course, I can call a function on a successful URL load using the following:

      // assume xml is a new XML instance and parseXML is the function called on a successful load
      xml.addEventListener(Event.COMPLETE, parseXML);

      What I can't figure out is if I can return a result directly - it doesn't look like it, as parseXML is called with an event:Event passed as a single argument.

      SO - is it possible, somehow, in AS3.0 to implement the following code in any given class:

      var menuObject:Object = DataManager.loadXML("someURL")

      Thanks for any help... understandable if you can't be arsed, but I'll be grateful.


      Steve J

      PS: Sorry for "non-code" display. Clicking "Attach Code" in Firefox 2 Mac OS X doesn't do anything.