Calendar

February 2008
M T W T F S S
« Jan   Mar »
 123
45678910
11121314151617
18192021222324
2526272829  

Tag Cloud

Categories

Archives

Highest Rated

Most Viewed

Recent Posts

Recent Comments


« 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, 2008Print This Post Print This Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
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.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" height="150">
  3.     <mx:Script>
  4.     <![CDATA[
  5.         import flash.filesystem.*;
  6.         private var stream:FileStream;
  7.         private function saveFile():void{
  8.             var file:File = File.desktopDirectory.resolvePath("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.         horizontalCenter="0" verticalCenter="0" />
  20. </mx:WindowedApplication>

Share/Save/Bookmark

Topics: Adobe AIR |

Comments