ActionScript 3 Loading External Files Loading a text file with FileStream (AIR runtime only)


A simple example on how to read a UTF text file synchronously.

import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

//First, get a reference to the file you want to load
var myFile:File = File.documentsDirectory.resolvePath("lifestory.txt");

//Create a FileStream object
fileStream = new FileStream(); 

//open the file, FileMode.READ);

//read the data and assign it to a local variable
var fileText:String = fileStream.readUTF();

//close the current filestream