0 Replies Latest reply on Nov 6, 2006 8:52 PM by QuickStick

    XML Loader

    QuickStick
      Hi all,

      Any help you can offer on this would be much appreciated... I'm tearing my hair out here.

      I'm trying to make a quick little function to load XML data from an individual url when called, and want to define:

      - The XML's url.
      - The variable to put the XML into.
      - The function to run after it is loaded.


      Have a look:

      <mx:Script>
      <![CDATA[

      //Alert class...
      import mx.controls.Alert;

      //Remote events class...
      import mx.rpc.events.*;

      //Remote http class...
      import mx.rpc.http.HTTPService;

      //New http service object...
      private var xmlService:HTTPService;

      [Bindable]

      //System configuration XML and variables...
      public var configXml:XML = new XML();

      public var ownerName:String = new String();


      //Load XML function (url to load from, function to run when loaded, error code to display)...
      public function loadXml(url:String, output:String, next:Function):void {

      //Create new http service...
      xmlService = new HTTPService();

      //Define the url to load XML from...
      xmlService.url = url;

      //Define the use of a proxy...
      xmlService.useProxy = false;

      //Format of the returned data...
      xmlService.resultFormat = "xml";

      //What to do when the data has loaded...
      xmlService.addEventListener("result", function(event:ResultEvent):void{

      //Put the loaded xml into the dynamic variable sent by the click function...
      this[output] = XML(event.result);

      //Run the next function...
      next();

      });

      xmlService.send();

      }

      public function showXml():void{

      Alert.show(configXml, "Configuration");

      }

      ]]>
      </mx:Script>


      Which is then called by something like:

      <mx:Button click="loadXml('configuration.xml', 'configXml', showXml);" />

      It works fine on using a dynamic function name (next - > showXml) but not on a dynamic variable name (output -> configXml)... however I don't think this is the problem, the problem comes in when it tries to write back to the configXMl variable, the scope of it is wrong, I have tried "this[output]", "[output]" and as many AS ways i can think of, but any suggestions would be great...

      FYI - The XML loads in fine, it just doesn't move from the "output" variable to the "configXml" variable.

      I would like to be able to define the variable the xml is outputted to from the function attached to the button.

      Any help is very much appreciated.

      Thanks
      Oz