9 Replies Latest reply on Mar 16, 2011 8:01 AM by saithus

    eval or array push problem?

    saithus

      This is an old AS2 program I have, and I am having some difficulties adding new features to it.


      Here's the code.

      I have a variable call php_variable that loads from the php.  It echos all the necessary variables.

      I have 2 array, Tel_start and Tel_area.

      The messages.text is just a text field I use to test if things are loading properly.

       

      php_variable.load("Telephone.php");

       

          for (var e = 0; e < num_ad; e++) {
              temp_loc = eval("php_variable.Tel_start"+(e+1));
              temp_last_loc = eval("php_variable.Tel_area_start"+(e+1));
              Tel_start.push(temp_loc);
              Tel_area_start.push(temp_last_loc);       
              messages.text = Tel_start[0];
          }

       

      When I use    //messages.text = eval("php_variable.Tel_start"+(e+1));

      It display the correct string.

      But when I use Tel_start[0] like above, I got undefined.

      So here, the actual quesetion, what's the proper way of storing those variables and displaying it?

        • 1. Re: eval or array push problem?
          kglad Adobe Community Professional & MVP

           

          php_variable.load("Telephone.php");

           

              for (var e = 0; e < num_ad; e++) {
                  temp_loc = php_variable["Tel_start"+(e+1)];
                  temp_last_loc = php_variable["Tel_area"+(e+1)];
                  Tel_start.push(temp_loc);
                  Tel_area_start.push(temp_last_loc);       
                  messages.text = Tel_start[0];
              }

           


          1 person found this helpful
          • 2. Re: eval or array push problem?
            saithus Level 1

            Thanks for the answer, but it doesn't seems to work for some reason .  I am still getting undefined for those text.  I am just curious as to why "messages.text = eval("php_variable.Tel_start"+(e+1));" was able to display the proper text but when I stored it in an array, it doesn't work like "messages.text = Tel_start[0]";  I need to retrieve those values from the array for later use.

             

            Thanks in advance

            • 3. Re: eval or array push problem?
              kglad Adobe Community Professional & MVP

              if the code i suggested doesn't work then you don't have those variables defined WHEN that code executed.  ie, there is no

               

              php_variable.Tel_start1;

              php_variable.Tel_start2;

              etc

               


              WHEN that code executes.

               

              HINT:  make sure that code doesn't execute until your loadvars is populated.

              • 4. Re: eval or array push problem?
                saithus Level 1

                Hi, Thanks for the reply.  Sorry for the trouble, am I not doing something that you told me to do??

                I have been following your code.  Please see the following for most of the coding I have on that particular page (I only left out those gotoAndStop("frame_2") things) and it's not working for some reason .

                 

                I have a similar AS3 program and it works fine, but this AS2 version just ain't working for some reason.

                 

                stop();

                 

                var php_variable = new LoadVars();
                php_variable.load("Telephone.php");
                var ad_status;
                var num_ad;
                var Tel_start:Array;
                var Tel_area:Array;

                 

                php_variable.onLoad = function (success) {
                   
                    if (success) {       
                        num_ad = php_variable.num_ad;
                        for (var e = 0; e < num_ad; e++) {
                                temp_loc = php_variable["Tel_start"+(e+1)];
                                temp_last_loc = php_variable["Tel_area"+(e+1)];
                                Tel_start.push(temp_loc);
                                Tel_area_start.push(temp_last_loc);      
                                messages.text = Tel_start[0];
                        }
                    } else {
                        messages.text = "Unable to load"
                    }   
                }

                 

                In the php, there are variables like this

                $num_ad = 5;

                $Tel_start1 = "icon1.jpg";
                $Tel_area1 = "905";

                 

                and their relative echos

                 

                I just want to have messages.text = Tel_start[0] to get "icon1.jpg" and it's just not working

                • 5. Re: eval or array push problem?
                  kglad Adobe Community Professional & MVP

                  use an onData method to see what's being returned from your php.

                  • 6. Re: eval or array push problem?
                    saithus Level 1

                    Thanks for the reply again.  I wasn't able to find this thread (I just realize there's a "Your stuff" thing up top" .

                     

                    Since I don't have experience using the onData method.  Is this what you mean using onData?  I did some research on my own and I don't seems to understand what you mean.

                     

                    Base on my previous codes, here's the onData function I wrote.

                     

                    php_variable.onData = function(raw) {
                        this.decode(raw);
                        this.onLoad();
                        messages.text = raw.toString();
                    }

                     

                    When I run the program, the textField returns to me some table code like the following with the variables I declared in php.

                     

                    <tr><th align='left' colspan='5' bgcolor='#e9b96e'>Variables in local scope (#1)</th></tr>
                    <tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$Tel_start1 =</pre></td><td colspan='3' bgcolor='#eeeeec'><pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>icon1.jpg'</font> <i>(length=9)</i>
                    </pre></td></tr>

                     

                    Base on my knowledge (Which is very limited), I believe Flash can load the values from the php but it just couldn't store the variable into the array using my code

                    • 7. Re: eval or array push problem?
                      kglad Adobe Community Professional & MVP

                      use:

                       


                       

                      php_variable.onData = function(raw) {

                          messages.text = raw;
                      }

                       


                      • 8. Re: eval or array push problem?
                        saithus Level 1

                        I just try it and it just return me those table like text like I mentioned a

                        bove.  Is there anything that I should be aware of?

                         

                        Thanks

                        • 9. Re: eval or array push problem?
                          saithus Level 1

                          Nevermind now, I figured out the problem and it was a dumb problem

                          The push wasn't working because the Array I declared wasn't able to store it properly.

                           

                          I use

                           

                          var Tel_start:Array;

                           

                          but the correct one is

                           

                          var Tel_start = new Array();

                           

                          Thanks for the help and sorry for the trouble.

                           

                          Message was edited by: saithus