Couple of bits of code for saving files using AIR:
This way does not open the save dialogue, just saves it automatically.
var stream:FileStream = new FileStream(); var saveFile:File = new File(); saveFile = saveFile.resolvePath(String(courseStructureURL)); var fileStream:FileStream = new FileStream(); fileStream.openAsync(saveFile, FileMode.WRITE); fileStream.writeUTFBytes(String(Structure.xml)); fileStream.addEventListener(Event.CLOSE, fileClosed); fileStream.close(); function fileClosed(e:Event):void { Utils.alert("The course has been updated successfully."); }
And this is the standard save way, where you select where to save it (standard flash way):
// this way uses a dialogue to save the file. try { saveFile.save(String(Structure.xml), "course_structure.xml"); Vars.unedited = true; // reset unedited - we've saved it! NB not perfect. runs everytime structure is updated, not everytime anything is changed. } catch (e:Error) { Utils.alert(String(e.errorID + ": " + e.message)); }
Obviously removing the contextual things in there!
Leave a Reply