Performing an auto-save with Adobe AIR with out a

2019-09-09 05:08发布

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

标签: file air save
1条回答
迷人小祖宗
2楼-- · 2019-09-09 05:35

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();
查看更多
登录 后发表回答