10 Replies Latest reply on Feb 6, 2010 2:00 PM by kglad

    LoadVars with many elements

    uomodicuore2

      Hi,

      I want to load data from a text file with four elements (account, first name, last name, club status).  There are 88,000 accounts.

       

      //Load the external data
      names=new LoadVars();
      names.load('db.txt');
      names.onLoad=function(){

      for(j=1;j<88001;j++){

       

      //declare and assign variables

      a[j]=names.a[j];        //account variables

      fn[j]=names.fn[j];      //first name variables

      ln[j]=names.ln[j];     //last name variables

      cs[j]=names.cs[j];   //club status variables

      }   //end for loop

      }//end onLoad function


      With the above, when I trace any values, it turns up undefined.

       

      Can anyone suggest a better way?  I am completely clueless about xml, mysql, php....sorry.

      Thanks!

      -Mark

        • 1. Re: LoadVars with many elements
          kglad Adobe Community Professional & MVP

          to test for errors, use:

           


           

          //Load the external data
          var sendLV:LoadVars=new LoadVars();

          var receiveLV:LoadVars=new LoadVars();

          receiveLV.onData=function(src){

           

          trace(src);

           

          }

           

          sendLV.sendAndLoad('db.txt',receiveLV,"POST");

           

          • 2. Re: LoadVars with many elements
            uomodicuore2 Level 1

            Thanks KGlad,

             

            Does that provide a sort of debug report?  I know the LoadVars works, as I can trace an individual item (e.g., names.a17 will result in the correct account number displaying).

             

            I'll try your advice at work tomorrow.

            -Mark

            • 3. Re: LoadVars with many elements
              kglad Adobe Community Professional & MVP

              it returns error messages (and the output) of your php file.

               

              but i see you're using a text file.  that's not very convenient.

               

              anyway, show the first few lines of your text file so we can see how it's setup.

              • 4. Re: LoadVars with many elements
                uomodicuore2 Level 1

                a1=1019670&fn1=John&ln1=Smith&cs1=50

                &a2=1020771&fn2=Jane&ln2=Jones&cs2=70

                ...a88000=1002589&fn88000=George&ln88000=Laney&cs88000=60

                 

                I can actually trace names.a88000....but it seems like the hangup is assigning them as variables within flash.  Not sure if I'm looping through them correctly.

                 

                 

                I thought about doing this and just declaring the elements of an array:

                a1=1019670,John,Smith,50

                &a2=1020771,Jane,Jones,70

                 

                 

                If you think I should be using php instead of text, I'll try that.  Would I declare the variables in php for each element like this?

                $a1=1019670;

                $fn1=John;

                $ln1=Smith;

                $cs1=50;

                 

                Any other advice would be greatly appreciated.

                • 5. Re: LoadVars with many elements
                  kglad Adobe Community Professional & MVP

                  try:

                   

                  //Load the external data
                  names=new LoadVars();
                  names.load('db.txt');
                  names.onLoad=function(){

                  for(j=1;j<88001;j++){

                   

                  //declare and assign variables

                  a[j]=names["a"+j];        //account variables

                  fn[j]=names["fn"+j];      //first name variables

                  ln[j]=names["ln"+j];     //last name variables

                  cs[j]=names["cs"+j];   //club status variables

                  }   //end for loop

                  }//end onLoad function

                  • 6. Re: LoadVars with many elements
                    uomodicuore2 Level 1

                    I tried the bit you advised earlier with the send/receive, and tracing the src didn't turn up anything...no error, no undefined.

                     

                    I tried the code you just suggested....interesting is that it results in undefined.  So, I tried the bit below just with a loop to create variables...but I changed a[j] as you can see below to "HI".  This should have resulted in 88,001 outputs of "HI", but instead they were all undefined.  So I'm thinking it's an issue with declaring the variables...

                     

                    Is there anything else I can try?  Sorry --- but thanks for helping!

                     

                     

                    //Load the external data
                    names=new LoadVars();
                    names.load('db.txt');

                    names.onLoad=function(){
                    trace(names.cs1);
                    for(j=1;j<88001;j++){
                    //declare and assign variables
                    //a[j]=names["a"+j];        //account variables
                    a[j]="HI";
                    trace(a[j]);
                    fn[j]=names["fn"+j];      //first name variables
                    ln[j]=names["ln"+j];     //last name variables
                    cs[j]=names["cs"+j];   //club status variables
                    }   //end for loop
                    }//end onLoad function

                    • 7. Re: LoadVars with many elements
                      kglad Adobe Community Professional & MVP

                      the code i gave will work as long as you've created all the arrays a, fn, ln and cs.  have you?

                      • 8. Re: LoadVars with many elements
                        uomodicuore2 Level 1

                        Ahh, didn't create the arrays - I'll do that now...Thanks for

                        your patience!

                        • 9. Re: LoadVars with many elements
                          uomodicuore2 Level 1

                          The arrays did it!  Thanks for all of your help!

                          • 10. Re: LoadVars with many elements
                            kglad Adobe Community Professional & MVP

                            you're welcome.