2 Replies Latest reply on Oct 14, 2010 6:52 AM by mlavie

    Text in Text File Can't be Loaded into a TextArea

    mlavie Level 1

      I am trying to do a very simple task: load the text contained in a text file to a TextArea. The file in question indeed exists.


      Below is my code. I hope someone can point out why the TextArea remains empty.






      The code:


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

         protected function myButton_clickHandler(event:MouseEvent):void
          var file:File = new File(); 
          file.url = "file:///C:/myTextFile.txt";
          var fileStream:FileStream = new FileStream();
          fileStream.open(file, FileMode.READ);
          var fileText:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
          myTextArea.text = fileText;

      <mx:Button x="116" y="193" label="Button" id="myButton" click="myButton_clickHandler(event)"/>
      <mx:TextArea x="85" y="25" width="251" height="109" id="myTextArea"/>