Reading files

AIR provides a file system API that can be used to read files of any type from the device.

In this recipe, we will see how to load a file previously written to the device.

Getting ready

If you haven't already done so, complete the Writing files recipe before proceeding.

You can continue to work with the code you wrote during that recipe. Alternatively, from the book's accompanying code bundle, open chapter13\recipe5\recipe.fla into Flash Professional and work from there.

How to do it...

Let us update the FLA's document class to load and display the preferences that were written to the device.

  1. Open the document class.
  2. Add a method that will load the preferences data:
    private function loadPreferences():void { file = File.documentsDirectory.resolvePath("prefs.txt"); ...

Get Flash iOS Apps Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.