6 Replies Latest reply on Feb 4, 2009 10:08 AM by Gregory Lafrance

    Can't read local data

    hsfrey Level 1
      I compiled the following simple program with -strict and -warnings, and it was clean.
      I have a file "data.txt" in the same folder.
      The program runs without complaint, but the data doesn't appear in the text area.
      Can anyone suggest a reason it fails?

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="initializeHandler(event)">
      <mx:Script> <![CDATA[
      private function initializeHandler(event:Event):void {textService.send( );}
      private function resultHandler(event:Event):void {textArea.text = String(textService.lastResult);}
      ]]> </mx:Script>
      <mx:HTTPService id="textService" url="data.txt" result="resultHandler(event)" />
      <mx:TextArea id="textArea" />
      </mx:Application>

      I have tried other sample programs, and none will read from a file in the same folder, though they will read from remote sites.
        • 1. Re: Can't read local data
          rtalton Level 4
          Hey there!
          Coupla thangs,
          1) Change resultHandler(event:Event) to resultHandler(event:ResultEvent)
          2) Be sure to add the import statement: import mx.rpc.events.ResultEvent;
          3) Use this line to the result handler: textArea.text = event.result.toString();
          4) Finally, go ahead and set the HTTPService's format tag to text: resultFormat="text"

          Attached is the working code. I would also resist naming things with existing component names (textArea).
          • 2. Re: Can't read local data
            hsfrey Level 1
            Thanks for the response!

            I made your suggested changes, but I still get no text displayed.
            I think I got them typed in right.
            I wonder if there's some Environment variable I don't know about.

            Here's the code as changed.

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
            layout="absolute" initialize="initializeHandler(event)">
            <mx:Script>
            <![CDATA[
            import mx.rpc.events.ResultEvent;
            private function initializeHandler(event:Event):void {
            textService.send( );
            }
            private function resultHandler(event:ResultEvent):void {
            textArea.text = event.result.toString();
            }
            ]]>
            </mx:Script>
            <mx:HTTPService id="textService" url="data.txt" result="resultHandler(event)" resultFormat="text" />
            <mx:TextArea id="textArea" />
            </mx:Application>
            • 3. Re: Can't read local data
              rtalton Level 4
              You'll have to debug it. Put a break in resultHandler and see if any data are being returned. You should see the data in the variables pane. If not...
              1) Where is data.txt located? Make sure data.txt exists and you have the correct path to it. Put the file somewhere inside your project, like maybe a folder named "data".
              2) You can also try a different data.txt file; make it real simple for testing...just a couple of words.
              3) Can you post the contents of data.txt so I can see it?
              • 4. Re: Can't read local data
                Level 7
                Your problem has to do with your security sandbox and the compiler switches
                that are used by Flex Builder when it's exporting a local build. Either use
                URLLoader instead, or you'll need to look up what the switch is and what its
                value should be.

                "hsfrey" <webforumsuser@macromedia.com> wrote in message
                news:gm5jif$j89$1@forums.macromedia.com...
                > Thanks for the response!
                >
                > I made your suggested changes, but I still get no text displayed.
                > I think I got them typed in right.
                > I wonder if there's some Environment variable I don't know about.
                >
                > Here's the code as changed.
                >
                > <?xml version="1.0" encoding="utf-8"?>
                > <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
                > layout="absolute" initialize="initializeHandler(event)">
                > <mx:Script>
                > <![CDATA[
                > import mx.rpc.events.ResultEvent;
                > private function initializeHandler(event:Event):void {
                > textService.send( );
                > }
                > private function resultHandler(event:ResultEvent):void {
                > textArea.text = event.result.toString();
                > }
                > ]]>
                > </mx:Script>
                > <mx:HTTPService id="textService" url="data.txt"
                > result="resultHandler(event)"
                > resultFormat="text" />
                > <mx:TextArea id="textArea" />
                > </mx:Application>
                >
                >


                • 5. Re: Can't read local data
                  hsfrey Level 1
                  Amy & rtalton:

                  I'm not using FlexBuilder, not least because I don't know what it's doing behind the scenes. I'm working down at the SDK level.

                  I suspect that you're right about the security sandbox. I'd like to know where I can twiddle that myself.

                  The data.txt file is in the same folder as the mxml and swf files. It is a simple text file that simply says "This is the data.txt file."

                  I didn't get any "file not found" error.

                  Harvey
                  • 6. Re: Can't read local data
                    Gregory Lafrance Level 6
                    Maybe instead of url="data.txt" you should provide the full URL of the data.txt file.