Symmetri Developer Blog

December 7, 2008

Writing a text file with Flex and AIR

Flash/Flex - By Shourov Bhattacharya

I have been developing in Flex and climbing the learning curve fast. The application I am building uses Adobe AIR to work both offline and online, and I need to save data locally into a text file as XML. The following is the ActionScript code I use to save a text file onto the desktop:

import flash.filesystem.File;
import flash.filesystem.*;
_
// set up fileName, xml
_
// create a file in the desktop folder
var file:File = File.desktopDirectory.resolvePath(this.fileName);
if (file.exists) file.deleteFile();
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTF(xml);
fileStream.close();

No surprises there; it’s clean, intuitive and completely in line with what one does in .NET. Permissions should not be a problem, as the AIR application takes on the privileges of the launching user. Aaron West has a \nice little write-up over at his blog that explains the basics of file access in AIR.

Comments »

No comments yet.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Janis Joseph