We Recommend

Essential ActionScript 3.0 Essential ActionScript 3.0
The book focuses on the core language and object-oriented programming, but also adds a deep look at the centerpiece of Flash Player's new API: display programming. Enjoy hundreds of brand new pages covering exciting new language features, such as the DOM-based event architecture, E4X, and namespaces--all brimming with real-world sample code.


Posted By

mswallace on 06/19/07


Tagged

file actionscript types 3 Reading AIR


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

bartekk
chrisaiv
copyleft
fukami
Akuma99


Reading Different File types with AS3


Published in: ActionScript 3 


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

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


  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

Report this snippet 

You need to login to post a comment.