0 Replies Latest reply on Mar 8, 2008 7:06 PM by John Hall

    File extension on Save

    John Hall Level 4
      Just starting with AIR and the browseForSave works fine except I can not figure out how to either make sure the user included the correct extension or to append an extension to the file name. Here's the code that works (from the help file). Is there anything I can do to grab control of the extension of the file name?

      if (event.item.@data == "save"){
      var docsDir:File = File.documentsDirectory.resolvePath("schedules/*.shd");
      try
      {
      docsDir.browseForSave("Save As");
      docsDir.addEventListener(Event.SELECT, saveData);
      }
      catch (error:Error)
      {
      trace("Failed:", error.message)
      }

      function saveData(event:Event):void
      {
      // WANT TO CHANGE FILE EXTENSION BEFORE SAVING
      var newFile:File = event.target as File;
      var str:String = "Hello.";
      if (!newFile.exists)
      {
      var stream:FileStream = new FileStream();
      stream.open(newFile, FileMode.WRITE);
      stream.writeUTFBytes(str);
      stream.close();
      }
      }

      }