Calendar

March 2007
S M T W T F S
« Feb   Apr »
 123
45678910
11121314151617
18192021222324
25262728293031

Tag Cloud

Categories

Archives

Recent Posts

Recent Comments


« 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
3,771 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
<?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>

Topics: Adobe AIR, Tutorials | 5 Comments »

5 Responses to “Write your first file to the file system using Apollo”

  1. Linda Rawson Says:
    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

    Reply to this comment

  2. everythingflex Says:
    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.

    Reply to this comment

  3. jason vancleave Says:
    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.

    Reply to this comment

  4. jason vancleave Says:
    July 8th, 2007 at 3:13 am

    doh! comment form stripped out my backslash in the new line comment

    Reply to this comment

  5. sh0509 Says:
    September 24th, 2009 at 4:49 am

    good!

    Reply to this comment

Comments