0 Replies Latest reply on Nov 6, 2007 7:00 AM by ljonny18

    Using XML with Flex - Best Practice Question

    ljonny18 Level 1

      I am using an XML file as a dataProvider for my Flex application.
      My application is quite large and is being fed a lot of data – therefore the XML file that I am using is also quite large.

      I have read some tutorials and looked thorough some online examples and am just after a little advice. My application is working, but I am not sure if I have gone about setting and using my data provider in the best possible (most efficient) way.

      I am basically after some advice as to weather I am going about using (accessing) my XML and populating my Flex application is the best / most efficient way???

      My application consists of the main application (MXML) file and also additional AS files / components.

      I am setting up my connection to my XML file within my main application file using HTTPService :

      url=" http://localhost/myFlexDataProvider.xml"
      result="myResultHandler(event)" />

      and handling my results with the following function:

      public function myResultHandler(event:ResultEvent):void
      myDataFeed = event.result as XML;

      within my application I am setting my variable values by firstly delacring them:

      public var fName:String;
      public var lName:String;
      public var postCode:string;
      public var telNum:int;

      And then, giving them a value by “drilling” into the XML, E;g:

      fName = myDataFeed.employeeDetails.contactDetails.firstName;
      lName = myDataFeed.employeeDetails.contactDetails.lastName;
      postCode = myDataFeed.employeeDetails.contactDetails.address.postcode;
      telNum = myDataFeed.employeeDetails.contactDetails.postcode;


      Therefore, for any of my external (components in a different AS file) components, I am therefore referencing there values using Application:

      import mx.core.Application;

      And setting the values / variables within the AS components as follows:

      public var fName:String;
      public var lName:String;

      fName = Application.application.myDataFeed.employeeDetails.contactDetails.firstName;
      lName = Application.application.myDataFeed.employeeDetails.contactDetails.lastName;

      As mentioned this method seems to work, however, is it the best way to do it??? :
      - Connect to my XML file
      - Set up my application variables
      - Give my variables values from the XML file ……

      Bearing in mind that in this particular application there are many variable that need to be set and there for a lot of lines of code just setting up and assigning variables values from my XML file.

      Could someone Please advise me on this one????

      Thanks a lot,