« Editing the Apollo Descriptor File | Main | File and FileStream within Apollo - full source code »
Write your first file to the file system using Apollo
By Rich Tretola | March 19, 2007
Print This Post
Print This Post1,876 views
Creating a file is very simple with Apollo. This is a very basic example of how to create a new file which is saved to the appStorageDirectory. Simply create a new Apollo project within FlexBuilder and paste the following as the main file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version=â€1.0″ encoding=â€utf-8″?>
<mx:ApolloApplication xmlns:mx=â€http://www.adobe.com/2006/mxmlâ€>
<mx:Script>
<![CDATA[
import flash.filesystem.*;
private var stream:FileStream;
private function saveFile():void{
var file:File = File.appStorageDirectory.resolve("HelloWorld.txt");
var stream:FileStream = new FileStream()
stream.open(file, FileMode.WRITE);
var str:String = "Congratulations on your 1st file, Rich Tretola - EverythingFlex.com";
stream.writeUTFBytes(str);
stream.close();
mx.controls.Alert.show("File has been saved to /n" + file.nativePath, "Notice");
}
]]>
</mx:Script>
<mx:Button label=â€Create File†click=â€saveFile()†/>
</mx:ApolloApplication>
<mx:ApolloApplication xmlns:mx=â€http://www.adobe.com/2006/mxmlâ€>
<mx:Script>
<![CDATA[
import flash.filesystem.*;
private var stream:FileStream;
private function saveFile():void{
var file:File = File.appStorageDirectory.resolve("HelloWorld.txt");
var stream:FileStream = new FileStream()
stream.open(file, FileMode.WRITE);
var str:String = "Congratulations on your 1st file, Rich Tretola - EverythingFlex.com";
stream.writeUTFBytes(str);
stream.close();
mx.controls.Alert.show("File has been saved to /n" + file.nativePath, "Notice");
}
]]>
</mx:Script>
<mx:Button label=â€Create File†click=â€saveFile()†/>
</mx:ApolloApplication>
Share this Post
Topics: Adobe AIR, Tutorials |


![[image]](http://mowser.com/img?url=http%3A%2F%2Fassets.max.adobe.com%2Fimages%2FMAX09_D125x125.jpg)




July 3rd, 2007 at 12:16 pm
Can you tell me what would be required from a user. Say a user worked at some computer security lockdown. What would the user need to run this application? For instance at most military installations they cannot run flash applications. Would they need flash to run this demo? Do they need admin privleges of any sort?
Linda Rawson
http://www.sensorytech.net
July 3rd, 2007 at 12:19 pm
They would require the AIR runtime, which includes the Flash Player and allow the application to have local access to read and write to and from the file system.
July 8th, 2007 at 3:11 am
Thanks, very helpful
in Flex 3/AIR appStorageDirectory has been changed to applicationStorageDirectory
you also probably wanted “n” instead of /n for a new line.
July 8th, 2007 at 3:13 am
doh! comment form stripped out my backslash in the new line comment