Save file in Adobe AIR without dialog window
Posted By :
Inder
| Posted At:
4/10/2010 3:16:04 AM
Tutorial: Save file without dialog window in Adobe AIR.
Technology: Adobe AIR, Adobe Flash, Flash Builder, Adobe Flex, Actionscript 3.0.
Description: Saving a file from flash without prompting the user is only possible in flash application running on Adobe AIR environment.Check the tutorial and example below.
Content: Following is the source code to write a file on a user system using flash. First we set the reference to the path where we want to save our text file. In this case I have set it to desktop directory. As soon as you execute this function from inside an Adobe AIR application you will find a test.txt file saved on your desktop without even prompting you for the save dialog window.
import flash.filesystem.*;
import flash.events.Event;
function saveFile():void {
var file:File=File.desktopDirectory;
file=file.resolvePath("test.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTFBytes("Hi this file was saved from AIR application without dialog");
fileStream.addEventListener(Event.CLOSE, fileClosed);
fileStream.close();
function fileClosed(event:Event):void {
trace("closed event fired");
}
}
saveFile();