Chapter 5. Working with the File System

AIR on iOS provides access to the file system to read, write, and update files of all types. This functionality can be very useful not only for reading existing files but also for storing files, media, data, and so on. This chapter will demonstrate how to read and write text files, browse the file system for media files, and create and write to an SQLite database.

File System Access

Just as in the desktop version of Adobe AIR, AIR on iOS provides you access to the file system. The usage is exactly the same.

Folder Aliases

To access the file system you can navigate using several folder static alias properties of the File class.

Let’s review the code below. On application complete, the application1_applicationCompleteHandler method is called and the static File properties are read and written to a String variable. This String variable is written to the text property of a TextArea component. Figure 5-1 shows the results:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                  xmlns:s="library://ns.adobe.com/flex/spark"
                  applicationComplete="application1_applicationCompleteHandler(event)">
    <fx:Script>
          <![CDATA[
               import mx.events.FlexEvent;

               protected function application1_applicationCompleteHandler(event:FlexEvent):void
               {
                     var s:String = "";                     s += "File.applicationDirectory : " 
+ File.applicationDirectory.nativePath + "\n\n";
                     s += "File.applicationStorageDirectory : " + File.applicationStorageDirectory.nativePath + ...

Get Developing iOS Applications with Flex 4.5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.