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

    HTTPSERVICE - text files


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





      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.



        • 1. Re: HTTPSERVICE - text files

          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. 



          • 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





            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="

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

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


              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("~");


              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, ""];