« Papervision3D: Part 1- Foundation and 3D Object Basics | Main | AIR FileSystem Components »
Write your first file to the file system using AIR
| By Rich Tretola | February 25, 2008 | Print This Post
|
| 55 views |
Creating a file is very simple with AIR. This is a very basic example of how to create a new file which is saved to the desktopDirectory. Simply create a new AIR project within FlexBuilder and paste the following as the main file.
- <?xml version="1.0" encoding="utf-8"?>
- <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" height="150">
- <mx:Script>
- <![CDATA[
- import flash.filesystem.*;
- private var stream:FileStream;
- private function saveFile():void{
- var file:File = File.desktopDirectory.resolvePath("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()"
- horizontalCenter="0" verticalCenter="0" />
- </mx:WindowedApplication>
Topics: Adobe AIR |







