1 Reply Latest reply on Nov 8, 2009 5:49 AM by Gregory Lafrance

    What is the best way to include external files in an application?

    erthy

      I am developing a vocabulary-training program (Adobe AIR using Flex Builder 3). Asks you what an equivalent of a czech word is in english and the other way. I am storing the "dictionaries" in external XML files. I would like to include about twenty of them in the installation. So far I just had them in the applicationDirectory, but now, I added an editing feature and I ran across the fact, that I cannot write into the applicationDirectory. So I figured the most intuitive place for the dictionaries would be in the documentsDirectory/name of program. However, how do I tell the AIR installation to make the according folder and include the files?

       

      How do I do this, or what do you think is a better solution? Thanks!

        • 1. Re: What is the best way to include external files in an application?
          Gregory Lafrance Level 6

          If this post answers your question or helps, please mark it as such.


          I'm creating an application that stores data in the "applicationStorageDirectory".      


          Mac storage directory is <appData>/<appId>/Local Store/
            where <appData> is user preferences folder, typically /Users/<user>/Library/Preferences


          Win: storage directory is <appData>\<appId>\Local Store\
            where <appData> is typically C:\Documents and Settings\<userName>\Application Data
            Note: Vista uses "junctions", which behave like shortcuts but look just like regular folders.
              It is not possible to access them, and any attempt to do so will give you an "Access Denied" error.
              Here is the real folder location:
                C:\Users\<userName>\AppData\Roaming\ContactManager\Local Store\contacts.xml


          Linux: <appData>/<appID>/Local Store/    where  <appData>  is  /home/<user>/.appdata


          Here is how to code to read from and write to a file there in an AIR app:


          var contactsFile:File;
          var contactsXML:XML;
          var contactsXLC:XMLListCollection;
          var stream:FileStream;

          contactsFile = File.applicationStorageDirectory;
          contactsFile = contactsFile.resolvePath("contacts.xml");

          stream = new FileStream();
          if (contactsFile.exists) {
              stream.open(contactsFile, FileMode.READ);
              contactsXML = XML(stream.readUTFBytes(stream.bytesAvailable));
              stream.close();
              contactsXLC = new XMLListCollection(contactsXML..contact);
          }else{
              var outputString:String = '<?xml version="1.0" encoding="utf-8"?>\n<contacts>\n';
              for each(var xml:XML in  contactsXLC){
                outputString += xml.toXMLString();       
                outputString += "\n";
              }
              outputString += "</contacts>\n";
              outputString = outputString.replace(/\n/g, File.lineEnding);
              stream = new FileStream();
              stream.open(contactsFile, FileMode.WRITE);
              stream.writeUTFBytes(outputString);
              stream.close();
          }