O'Reilly logo

Professional Adobe® Flex® 3 by Joe Berkovitz, David Hassoun, Andrew Trice, Tom Sugden, Todd Prekaski, Jun Heider, Peter Ent, Joseph Balderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 45. Local File Management with AIR

The AIR extensions to Flex include the ability to work with files and directories. AIR applications can access the user's filesystem to create, delete, read, and write files, as well as perform a variety of directory operations such as create, delete, move, list files, and so forth.

In addition, AIR will interact with operating system-specific dialog boxes for picking files, saving files, and browsing directories, giving your AIR application an authentic feel in the user's operating system of choice.

This chapter covers working with files and directories, the native dialog boxes, specific Flex components designed to work with filesystems, and a specific method for encrypting data saved on the user's hard drive.

File Operations

Most of the File operations available to AIR are accessed through the flash.filesystem.File class — everything from listing, copying, moving, and deleting files and directories to working with special operating system directories like the user application. The File class is a pointer used to represent either a path to a directory or a specific file. Once you're pointing at either a file or directory, you then pass the reference into the rest of the APIs, such as FileStream for reading a file or File.getDirectoryListing for listing all the files in a given directory.

Referencing Directories

As an example, here is a File object that represents a directory:

var file:File = File.documentsDirectory.resolvePath("My Pictures"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required