Calendar

March 2007
M T W T F S S
« Feb   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

Tag Cloud

Categories

Archives

Highest Rated

Most Viewed

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, 2007Print This Post Print This Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
815 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. <?xml version=”1.0″ encoding=”utf-8″?>
  2. <mx:ApolloApplication xmlns:mx=”http://www.adobe.com/2006/mxml”>
  3. <mx:Script>
  4. <![CDATA[
  5. import flash.filesystem.*;
  6. private var stream:FileStream;
  7. private function saveFile():void{
  8. var file:File = File.appStorageDirectory.resolve("HelloWorld.txt");
  9. var stream:FileStream = new FileStream()
  10. stream.open(file, FileMode.WRITE);
  11. var str:String = "Congratulations on your 1st file, Rich Tretola - EverythingFlex.com";
  12. stream.writeUTFBytes(str);
  13. stream.close();
  14. mx.controls.Alert.show("File has been saved to /n" + file.nativePath, "Notice");
  15. }
  16. ]]>
  17. </mx:Script>
  18. <mx:Button label=”Create File” click=”saveFile()” />
  19. </mx:ApolloApplication>

Share/Save/Bookmark

Topics: Adobe AIR, Tutorials |

4 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

  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.

  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.

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

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

Comments