1 Reply Latest reply on Aug 4, 2007 2:08 PM by klintonray

    Best Practice Question ???

    mrSparkleS0ap Level 1
      Is there another way to define a XML.onLoad function?

      I like to keep my code neat and I was experimenting with ways to write a XLM.onLoad function without including the function definition with another function...

      In the Article "ActionScript 2.0 Best Practices"
      http://www.adobe.com/devnet/flash/articles/as_bestpractices_04.html

      Jen has this code for loading XML withing a AS 2.0 class:

      var thisObj:Product = this;
      // Create a local variable, which is used to load the XML file.
      var prodXml:XML = new XML();
      prodXml.ignoreWhite = true;
      prodXml.onLoad = function(success:Boolean) {
      if (success) {
      /* If the XML successfully loads and parses,
      set the class's m_products_xml variable to
      the parsed XML document and call the init
      function. */
      thisObj.m_products_xml = this;
      thisObj.init();
      } else {
      /* There was an error loading the XML file. */
      trace("error loading XML");
      }
      };

      Is there a way to do something like ? :
      class appXMLloader{

      function MyXMLloader(){
      var thisObj:Product = this;
      // Create a local variable, which is used to load the XML file.
      var prodXml:XML = new XML();
      prodXml.ignoreWhite = true;
      prodXml.onLoad = myParser;
      }
      function myParser(success:Boolean) {
      if (success) {
      /* If the XML successfully loads and parses,
      set the class's m_products_xml variable to
      the parsed XML document and call the init
      function. */
      thisObj.m_products_xml = this;
      thisObj.init();
      } else {
      /* There was an error loading the XML file. */
      trace("error loading XML");
      }
      }

      }

      could you use delegate?