Save File in AS3

Opens a dialog box that lets the user save a file to the local filesystem. Although Flash Player has no restriction on the size of files you can upload, download, load or save, the player officially supports sizes of up to 100 MB.

The save() method first opens a dialog box that asks the user to enter a filename and select a location on the local computer to save the file. once Selected and confirms the save operation (for example, by clicking Save), the save process begins. Listeners receive events to indicate the progress, success, or failure of the save operation.

FileReference save method has only to be invoked upon user interaction, for example by a mouse click or button press.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”” layout=”absolute” >
private var file:FileReference = new FileReference();
private function onCreate(e:Event):void
var Txt:String=”Hello World”,”Sample.txt”); // Initiates the save event and opens up a dialog box for user to enter filename and select a location. Once confirmed, it get saved
} ]]>
<mx:Button x=”133″ y=”209″ label=”Create File” click=”onCreate(event)”/>

Save File in Adobe Flex -AIR

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:WindowedApplication xmlns:mx=”” layout=”absolute” creationComplete=”onCreate(event)”>
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
function onCreate(e:Event):

var file:File = File.desktopDirectory; //Set the Directory location to Desktop
file = file.resolvePath(
“test.txt); //File Name
fileStream:FileStream = new
FileStream();   // Create new FileStream to Perform Read or Write, FileMode.WRITE); // Open file in WRITE Mode
“Hello World”); //Write Hello World into test.txt
fileStream.close(); //Close the File Stream


This code creates a file named test.txt with content “Hello World” in desktop folder.

The desktopDirectory property provides a way to reference the desktop directory that works across platforms. If you set a File object to reference the desktop directory using the nativePath or url property, it will only work on the platform for which that path is valid Similarly documentDirectory /applicationStorageDirectory /applicationDirectory can be used to represent the folder.

var file:File = new File();
file = file.resolvePath(

This will work in windows platform and stores file in user mentioned location.