AIR provides a file system API that can be used to write files of any type to the device.
Let us see how to write a text file containing simple preferences data that might, for example, be used by a game.
An FLA has been provided as a starting point for this recipe.
From the book's accompanying support files, open chapter13\recipe4\recipe.fla
into Flash Professional.
Sitting on the stage is a dynamic text field named output
. We will write some preferences data to the device and use the text field to indicate when the data has been written.
The flash.filesystem
package contains classes that provide file system access. Let us make use of some of those classes to write to the device.
Create a document class and name it
Main
.Import the following classes:
import flash.display.MovieClip; import flash.events.Event; import flash.events.IOErrorEvent; import flash.filesystem.File; import flash.filesystem.FileMode; import flash.filesystem.FileStream;
Add a
File
and...