7 Replies Latest reply on Feb 1, 2007 10:15 AM by jonnybennett

    Odd variable behavior (PHP)

    mtg169 Level 1
      I have created a PHP script (getVars.php) to generate some variables to load into Flash. I have no problem with this and basically echo something similar to the following:
      ID=10002&Name=Joe Schmoe&Email=joe@schmoe.com&Check=True

      What I am trying to do is have a certain movie load based on the value of the "Check" variable. My Actionscript looks like the following:

      loadVariables("getVars.php", _root);
      if (Check != "True"){
      loadMovie("nonpay.swf", _root);
      }
      else
      loadMovie("paid.swf", _root);

      The problem is that "nonpay.swf" is always loaded regardless of whether "Check" is True or False. As a test, I removed the conditional statements altogether and created a dynamic textbox to display the value of "Check". It displays the correct value all the time based on what is being passed to it from "getVars.php". For some reason, when I add the conditional statements, there is no value displayed in the textbox, although it flashes pretty quick so maybe it just doesn't have enough time to load. It seems like something odd is happening to the "Check" variable when the conditional statements are called and it's been driving me nuts. I haven't done much with Actionscript in quite some time, so maybe I am just not loading the variables or movies properly. Any help is greatly appreciated.
        • 1. Re: Odd variable behavior (PHP)
          Level 7
          mtg169 wrote:
          > I have created a PHP script (getVars.php) to generate some variables to load
          > into Flash. I have no problem with this and basically echo something similar to
          > the following:
          > ID=10002&Name=Joe Schmoe&Email=joe@schmoe.com&Check=True

          echo 'ID=10002&Name='.urlencode('Joe
          Schmoe').'&Email='.urlencode('joe@schmoe.com').'&Check=True';

          Non-standard characters need to be URL encoded.

          --
          David Powers, Adobe Community Expert
          Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
          Author, "PHP Solutions" (friends of ED)
          http://foundationphp.com/
          • 2. Odd variable behavior (PHP)
            mtg169 Level 1
            The URL encoding did not fix the problem. The same data is still output and formatted exactly the same by my PHP script. It just appears to be a problem with loading the correct movie based on the value of "Check".

            As stated previously, I have the "Check" variable displayed for testing just as "Check=" and then a dynamic text box with var set to Check right next to it to display the value. It displays the correct value fine without the conditional statements, but displays no value with the conditional statements (it flashes quickly, but all I see is Check= and no value after it). It then loads nonpay.swf regardless if Check is set to True or False in my PHP script.

            I'm stumped. Does anyone see a problem with how I am loading the movies or the Actionscript?

            BTW: I am using MX Professional 2004.

            I have also tried the conditional statement like the following, with the same results:

            if (Check == "True"){
            loadMovie("paid.swf", _root);
            }
            else
            loadMovie("nonpay.swf", _root);
            • 3. Re: Odd variable behavior (PHP)
              jonnybennett Level 1
              That was a weird problem, took me a while of trial and error, however for some reason becuase it is on the end of the php string it is not evaluating it properly unless you add an extra '&' on the end of your echo....
              therefore php should read:

              echo '&ID=10002&Name=JoeSchmoe&Email=joe@schmoe.com&Check=True&'

              then it works. Dunno why though. Hope that helps J.
              • 4. Re: Odd variable behavior (PHP)
                mtg169 Level 1
                I don't think it's a problem with how the PHP string is formatted. It's formatted correctly and I am able to view/display all of the variables fine in Flash. I tried your suggestion anyway and still have the same results. I think it may be a problem with how I am loading/referencing the variables in the Flash Actionscript. If the value of Check is always false (even though it really is not) it's like it doesn't exist when I reference it in the conditional statement.
                • 5. Odd variable behavior (PHP)
                  jonnybennett Level 1
                  with the php as above and with the following actionscript to load the variables from php into flash using loadVars(), i can get a conditional statement to work based on the Check variable:

                  tom=new LoadVars();

                  tom.onLoad=function(){
                  if (tom.Check=='true'){
                  tester.text=tom.Check+'hello';}
                  if (tom.Check!='true'){
                  tester.text=tom.Check+'goodbye';}
                  }

                  tom.load("getVars.php");

                  hope this works for you.
                  • 6. Re: Odd variable behavior (PHP)
                    mtg169 Level 1
                    Using loadVars() solved the problem entirely. Many thanks to you!
                    • 7. Re: Odd variable behavior (PHP)
                      jonnybennett Level 1
                      welcome.