4 Replies Latest reply on May 9, 2007 4:49 PM by BLXWebMaster

    Load Data from External .txt file

    compubrook Level 1
      <mx:Script>
      <![CDATA[
      import flash.display.Sprite;
      import flash.events.*;
      import flash.net.URLLoader;
      import flash.net.URLLoaderDataFormat;
      import flash.net.URLRequest;


      [Bindable] public var i:int = 20;
      [Bindable] public var tester:int = 0;

      var loader:URLLoader = new URLLoader(new URLRequest("test.txt"));

      private function completeHandler(event:Event):void
      {
      var loader2:URLLoader = URLLoader(event.target);
      var variables:URLVariables = new URLVariables(loader2.data);
      trace(variables.xyz);
      tester = variables.xyz;
      }
      ]]>
      </mx:Script>

      I'm trying to read in data from an external text file. Is there any reason why this isn't working?
        • 1. Re: Load Data from External .txt file
          compubrook Level 1
          Can someone please take a look at this? It is taken from the example in the help file.

          • 2. Re: Load Data from External .txt file
            BLXWebMaster Level 1
            If you simply need to read a text file, I would go about it like this....
            <mx:Application
            xmlns:mx=" http://www.adobe.com/2006/mxml"
            layout="absolute"
            initialize="myService.send()">

            <mx:Script>
            <![CDATA[
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var myData:String;

            private function resultHandler(event:ResultEvent):void {
            myData = myService.lastResult.toString();
            }
            ]]>
            </mx:Script>

            <mx:HTTPService id="myService" url="test.txt" result="resultHandler(event)"/>
            <mx:Text id="something" text="{myData}"/>
            </mx:Application>

            Allen
            • 3. Load Data from External .txt file
              compubrook Level 1
              Thanks for your help!

              What I'm trying to do is be able to read in the two addresses for 2 HTTPServices.

              the text file would be:

              pSrv=http://localhost/gbkiosk/getdata.php?length=day&pSrv2=http://localhost/gbkiosk/getdat a.php?length=week


              then my serrvice calls would loo like this

              <mx:HTTPService id="pSrv"
              url={pSrv}
              />
              <mx:HTTPService id="pSrv2"
              url={pSrv2}
              result="chartComplete(event)"
              />
              • 4. Re: Load Data from External .txt file
                BLXWebMaster Level 1
                Can you use an XML file instead of a text file. I think you are going to run into a lot more work if you are trying to parse a text file and extract the information you want the way you want it. This one is fine beacuse it contains only 1 "&" which you can use as a delimiter. Much easier if the file was a XML file.

                Here is a quick working example using split.
                <mx:Application
                xmlns:mx=" http://www.adobe.com/2006/mxml"
                layout="absolute"
                initialize="myService.send()">

                <mx:Script>
                <![CDATA[
                import mx.rpc.events.ResultEvent;

                [Bindable]
                private var myData:String;
                [Bindable]
                private var myArray:Array;

                private function resultHandler(event:ResultEvent):void {
                myData = myService.lastResult.toString();
                myArray = myData.split('&');
                }
                ]]>
                </mx:Script>

                <mx:HTTPService id="myService" url="test.txt" result="resultHandler(event)"/>
                <mx:Text id="something" text="{myArray[0]}"/>
                <mx:Text id="something1" text="{myArray[1]}" y="26"/>
                </mx:Application>