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;
  4.  
  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
  7.  
  8. var fileStream:FileStream = new FileStream(); // Create our file stream
  9. fileStream.open(myFile, FileMode.READ);
  10.  
  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
  13.  
  14. fileStream.close(); // Clean up and close the file stream

URL: http://office.realeyesmedia.com/blogs/john/index.php/2007/05/26/reading-a-file-with-actionscript-3/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.