3 Replies Latest reply on Nov 5, 2009 7:43 AM by oldMster

    HTTPSERVICE - text files

    1advent

      Is there anyway to get Flex to pull from a text file that looks like this:

      array=23~50~-33~-50~23~~narrower=Independent~ip=63.230.216.19

      array=11~40~-36~-50~53~~narrower=Republican~ip=41.200.216.19

      array=23~50~-23~--34~38~~narrower=Democrat~ip=69.20.216.19

       

      I basically want to pull a row, split it into an array named after the "narrower" SOOOO

      it would be Independent array is 23, 50, 33, -50, 23 when i am done.

       

      I'm sorry i know its a lot, but the biggest feat i need is to be able to pull a row from the data file, and split it into two strings each.

       

      thanks if anyone has an idea.

       

      Josh

        • 1. Re: HTTPSERVICE - text files
          Louder6Pounder

          I'm not entirely sure this is what you mean, but could you not just create a JSON object array and pass it to Flex through the flashvars or external interface. 

           

          Then you can use the JSON libs to decode it as an object in flex and iterate through all the properties you have parsed. 

           

          ldb.

          • 2. Re: HTTPSERVICE - text files
            Matt Le Fevre Level 4

            Personally, if i was doing this...

             

            i'd write a php script which would read the contents of the text file and put it into a string

             

            chop the string into the relevant bits using the Split function and then output into XML and send back to the flex app in this format

            <Array>
                 <Name>Independent</Name>
                 <IP>63.230.216.19</IP>
                 <Arr1>23</Arr1>
                 <Arr2>50</Arr2>
                 <Arr3>-33</Arr3>
                 <Arr4>-50</Arr4>
                 <Arr5>23</Arr5>
            </Array>
            
            <Array>
                 <Name>Democrat</Name>
                 <IP>69.20.216....
            
            etc..
            

             

             

             

            although thats just due to my familiarity of PHP.

             

            i'm sure there are alot more (and probably easier) ways to do this. For example you could pass the entire string back into Flex and handle it there, try researching into the flex 'split' function.

            1 person found this helpful
            • 3. Re: HTTPSERVICE - text files
              oldMster Level 3

              Try this (disclaimer, i haven't tested it)

               

              private function procResult(event:ResultEvent):Array {

              //  assumes result from httpService is a text, not e4x, XML, etc

              var temp1:Array = event.result.split("array=");

              // should now have temp1[0]="",

              //                 temp1[1]="23~50~-33~-50~23~~narrower=Independent~ip=63.230.216.19"

              //                 temp1[2]="11~40~-36~-50~53~~narrower=Republican~ip=41.200.216.19"

              //                 temp1[3]="23~50~-23~--34~38~~narrower=Democrat~ip=69.20.216.19"

               

              var tempindex:int;

              var temp2:Array;

              var temp3:Array;

              var tempkey:String;

              var dataarray:Array;

              for (tempindex = 1 ; tempindex++ ; tempindex < (temp1.length+1) ) {

              temp2 = temp1[tempindex].split("narrower=");

              temp3 = temp2[1].split("~");

              tempkey=temp3[0];

              temp3 = temp2[0].split("~");

              dataarray[tempkey] = temp3;

              }

               

              return dataarray;

              }

               

              // should result in:

              //dataarray["Independent"] = [23, 50, 33, -50, 23, ""];

              //dataarray["Republican"] = [11, 40, -36, 50, 53, ""];

              //etc.