问题
I've an AIR app that I'd like to implement a auto-save functionality. Currently I have a service that uses a timer to check the status of the current active file in my app, then if the file changes to a new file, the service checks the current file name if that has changed then the file has changed. When this happens I want to perform a auto-save, which I can do but the problem is that the save popup save box opens when the save is called, this is how I call the save function:
var file:File = File.userDirectory.resolvePath( filepath ); file.save( jsonToExport );
Is there a way to call the save() function without a popup box opening?
Thanks
Stephen
回答1:
Rather than using the File's save method, try using a FileStream to write the file directly:
var file:File = File.userDirectory.resolvePath( filepath );
//Instantiate new file stream
var fs:FileStream = new FileStream();
//add optional event listener to do some action once finished
fs.addEventListener(Event.CLOSE, fileWrittenComplete);
//open the file in write mode
fs.openAsync(file, FileMode.WRITE);
//write your data to file
fs.writeUTFBytes(jsonToExport);
//close the file stream
fs.close();
来源:https://stackoverflow.com/questions/9411230/performing-an-auto-save-with-adobe-air-with-out-a-popup-save-box-opening