Search

 

February 2008
S M T W T F S
« Jan   Mar »
 12
3456789
10111213141516
17181920212223
242526272829  

Tags

Archives


« | Main | »

Write your first file to the file system using AIR

By Rich Tretola | February 25, 2008
4,855 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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 | No Comments »

Comments