Adobe AIR - Load local text file


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



Copy this code and paste it in your HTML
  1. public var file:FileReference = new FileReference();
  2.  
  3. public function doLoad( event:Event ):void
  4. {
  5. file.addEventListener( Event.SELECT, doFileSelect );
  6. file.addEventListener( Event.COMPLETE, doFileComplete );
  7. file.browse( [new FileFilter( "Text File", "*.txt" )] );
  8. }
  9.  
  10. public function doFileSelect( event:Event ):void
  11. {
  12. file.load();
  13. }
  14.  
  15. public function doFileComplete( event:Event ):void
  16. {
  17. // txtField is the instance name of a text field used to display loaded content.
  18. txtField.text = file.data.readMultiByte( file.data.bytesAvailable, "utf-8" );
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.