1 Reply Latest reply on Dec 13, 2010 9:07 PM by celebritymusic

    Importing XML using AS3 and AIR

    celebritymusic Level 1

      Hi

       

      I'm creating two separate AIR projects.  I'd like them both to be able to access the same XML file that's residing in the user's document's folder.

       

      Before, I''ve successfully set up importing XML using URLLoader etc, but this method won't work when trying to access an XML from outside of an air project (I think).

       

      So is it possible to imporrt an XML file using something like:

       

          var loadXMLfile:File = File.documentsDirectory;
          loadXMLfile = loadXMLfile.resolvePath("display_list.xml");

       

      ...and then somehow direct loadXMLfile into an XML parser?

       

      Thanks

       

      Shaun

        • 1. Re: Importing XML using AS3 and AIR
          celebritymusic Level 1

          Nevermind - here's the code for anyone interested:

           

          Normally with URLLoader you'd do this:

           

          // new instance of URLLoader class
          var myXMLloader:URLLoader = new URLLoader();

           

          myXMLloader.load( new URLRequest( 'common_upload_files/XML_files/120_display_list.xml' ));  ...wherever the XML file is relative to the project swf


          // add event listener to instance to issue event when finished loading xml
          myXMLloader.addEventListener( Event.COMPLETE, onXMLLoaded_120 );

           

          ...where onXMLLoaded_120 would deal with parsing the xml data.

           

          To do the same in AIR:

           

          var loadXMLfile:File = File.documentsDirectory.resolvePath("PlugTV Media Files/120_display_list.xml");   ...the XML file is in the user's 'Documents' directory (works on Win, Mac, Linux)

          // Pass the file.url property to the URLRequest constructor
          var myXMLloader:URLLoader = new URLLoader(new URLRequest(loadXMLfile.url));
          myXMLloader.addEventListener(Event.COMPLETE, onXMLLoaded_120)   

          ...where onXMLLoaded_120 would deal with parsing the xml data.