7 Replies Latest reply on Aug 12, 2014 4:22 AM by kglad

    php variables loaded into flash correctly and displayed DEFY the If - Then statements

    AjooSehgal

      path = "http://localhost/xampp/nwjv/php/";

       

      //declare path to php files

      lvOut = new LoadVars();     //create lv object sending variables OUT to php

      lvIn = new LoadVars(); //create lv object receiving variables IN from php 

       

      lvIn.onLoad = function (success) {

      if(success)

      {

           //PHP variable value to textbox 

       

           InVal = lvIn.returnVal;

           InTxt = lvIn.retVal; 

       

           output.text = InVal;

           output1.text = InTxt; 

          

           /* 

          output1.text = "No Value"; 

           if(InTxt == 'lo' ) { output1.text = "Low Value"; } 

           if(InTxt == 'hi') { output1.text = "High Value"; }

            */

      } else { //...or notify of failure output.text = "fail"; }

       


      myBtn.onRelease = function()

        {

            //assign user-input value to lv property called years

           lvOut.years = years.text; //send to a blank window //

           lvOut.send(path + "dogyears_new1.php",lvIn,"GET");

           lvOut.sendAndLoad(path + "dogyears_new1.php",lvIn,"GET");

      };

       

      And the simplest PHP code

       

      PHP Code:

       

      <?php$calculation = $_GET["years"]*2;
      if(
      $calculation <=10 ) $retVal="lo";
      if(
      $calculation > 10$retVal="hi";
      echo
      "&returnVal=$calculation &retVal=$retVal" ;?>

       

       

      PHP returns two values which are collected by flash in variables InVal and InTxt. The values collected are correct and are displayed thus in the 2 output boxes. If value in the Input Box is 5 or less the outbox1.text shows 'lo' and if the Input Box is greater than 5 the output1.text shows 'hi'.

       

      Now, if the commented out If then block in the code is activated by removing the /* */ from around it and the program is run, the If Then block fails since the comparison of InTxt fails.  SO even though the value of InTxt is 'hi' or 'lo' as can be seen on the 1st run, yet the value does not change to the corresponding 'High Value'or 'Low Value' depending upon the value of InTxt in the If Then comparison bloac.


      It completely fails me why this is happening. While I can display the values correctly, I can't use them in conditional loops. I have even tried them in switch case statements with the same frustrating result. ( The output1.text remains equal to "No Value" when it should change to either "High Value " or "Low Value")

       

      Earlier I was using numbers and when that failed I tried to use strings since I thought that for some reason PHP returns everything as strings. But as can be seen, even the string comparison fails.

       

      Can someone please comment on this behavior and suggest a solution.

      Thanks loads all !


      PS. I wanted to upload the small fla for this but I could not find a way to add a file here. Please suggest if i can do so and how and I will upload my fla for this code. Thanks.