Reading Different File types with AS3

/ Published in: ActionScript 3
Save to your folder(s)

Found this code. It is an example of loading and reading different file types with ActionScript 3

Copy this code and paste it in your HTML
  1. import flash.filesystem.FileMode;
  2. import flash.filesystem.FileStream;
  3. import flash.filesystem.File;
  5. var myFile:File = File.appResourceDirectory; // Create out file object and tell our File Object where to look for the file
  6. myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file
  8. var fileStream:FileStream = new FileStream(); // Create our file stream
  9., FileMode.READ);
  11. var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable); // Read the contens of the
  12. fileContents_txt.text = fileContents; // Display the contents. I've created a TextArea on the stage for display
  14. fileStream.close(); // Clean up and close the file stream


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.