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.
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.
Let us update the FLA's document class to load and display the preferences that were written to the device.
Open the document class.
Add a method that will load the preferences data:
private function loadPreferences():void { file = File.documentsDirectory.resolvePath("prefs.txt"); stream = new FileStream(); stream.addEventListener(IOErrorEvent.IO_ERROR, ioError); stream.addEventListener(Event.COMPLETE, fileLoaded); stream.openAsync(file, FileMode.READ); }
Alter the class'
fileSaved()
handler...