5 Replies Latest reply on Feb 21, 2007 4:04 PM by maxtkacz

    LoadVars and php problems

    maxtkacz
      Okay, I tried using flashvars to get info from the html file my quiz game i embedded in and then tried to do an if statement that always returned false so I tried using loadVars() to load from a php script and have the same problem which is that the variable from the php script equals a certain number (a dynamic textbox) which is 1 for instance then I do an if statement using this variable to see if it equals one and it always returns false, this happens with any external variables I load. Help!
        • 1. Re: LoadVars and php problems
          Level 7
          Here's about the simplest example I can come up with to get a variable into
          Flash from a PHP page.

          In Flash on frame 1:

          var receiver = new LoadVars();
          var sender = new LoadVars();

          receiver.onLoad = function(success:Boolean){
          if(success){
          trace(this.phpvar); //traces 6 with this example.
          }
          }
          sender.avar = 3;
          sender.sendAndLoad(" http://www.blurredistinction.com/test/doubleinput.php",
          receiver);
          stop();


          Then, in doubleinput.php:

          <?PHP
          $in = $_REQUEST['avar'];
          $in *= 2;
          echo("&phpvar=$in");
          ?>


          Couple things to note - any variables you send in (sender.avar) need to
          match the variable names in the $_REQUEST or $_POST of the PHP page. Same
          for the variables you send back to Flash - note that I send phpvar back to
          flash, and trace that in the onLoad function.


          HTH

          --
          Dave -
          Head Developer
          www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: LoadVars and php problems
            maxtkacz Level 1
            I do that and the variable loads but flash will always make any if statement using imported variables (flashvars or onLoad()) as a false statement, I don't know what to do.
            • 3. Re: LoadVars and php problems
              SymTsb Level 2
              it's because it probably doesn't exist. place your if statements inside the receiver.onLoad function. You can't test anything until that data has been streamed into Flash. I had similar problems for 2 hours before figuring that out so try that out and see what happens.
              • 4. Re: LoadVars and php problems
                Level 7
                Like SymTsb said, you are dealing with asynchronous communication here -
                until onLoad fires the variables don't exist. In the example I gave you, if
                you say if(this.phpvar){ it will execute the statements in the if just fine
                since the value is 6. Try tracing the variable before you test it.

                --
                Dave -
                Head Developer
                www.blurredistinction.com
                Adobe Community Expert
                http://www.adobe.com/communities/experts/


                • 5. Re: LoadVars and php problems
                  maxtkacz Level 1
                  Will try but the variable is used in the next scene and the loadVars plays the rest of the movie only after loading is complete, also I have a dynamic textbox that displays the loaded variable before its used in the if statement and it displays the right number to make the if statement true, but the statement returns false!