3 Replies Latest reply on Nov 14, 2010 1:29 PM by christoferdutz

    Need help with loading XML file




      I have been browsing the web/forums for an example on how to do this for a few days now.  I managed to get this working in Flash Pro quite easily but I think I am missing something when I want to do the same thing in Flex.


      Basically I want to load an XML file and then set the text values of 5 labels equal to the data in the XML file.



      So I a button created in MXML and have set the click event as follows:




      I have also declared the following:


           public var myRequest:URLRequest = new URLRequest("assets/myFile.xml");   //folder located under src in project

           public var myLoader:URLLoader = new URLLoader();

           public var myXML:XML;



      My function that loads is as follows:


      public function dsSetup(event:MouseEvent):void


           trace ("dsSetup");

           myXML = new XML (myLoader.data);



           h3.text = myXML.source.itemA;

           h4.text = myXML.source.itemB;

           h5.text = myXML.source.itemC;

           h7.text = myXML.source.itemD;

           h8.text = myXML.source.itemE;



           currentState = 'MainMenu';





      myLoader.addEventListener(Event.COMPLETE, dsSetup);   // I think this line is now redundant as I have set it in the MXML




      This is the way I did it in Flash and it worked ok but I must be missing something in when it comes to Flex.


      Can someone explain or point me to a good tutorial that shows how to load XML in Flex? 

      The ones I found seem to have about 50 lines of code just to load a file and add in way to much complexity for a beginner.




      Many Thanks