3 Replies Latest reply on Mar 25, 2008 5:39 PM by kglad

    Flash to PHP using LoadVars.send

    akiva.kent Level 1

      For the life of me, I've tried everything:
      I've researched LoadVars on Adobe forum, used David Powers' books, googled 'flash to php', LoadVars, etc. and tried sendAndLoad, send, and using $_POST, $_GET, $_REQUEST. $HTTP_POSTVARS but I keep getting this same error. any advice please?

      I have a Unix server running Apache/PHP 4 - LoadVars worked to load name-value pairs into an array -see thread)

      My goal with this simple app is to prototype being able to pass a variable from flash to a variable in php.

      Parse error: syntax error, unexpected T_VARIABLE in flash_to_SQL.php on line 5

      Actionscript 2.0 code:

      var c :LoadVars = new LoadVars();
      c.testing = "123FOUR";
      c.send (" http://127.0.0.1/flash_to_SQL.php","_self","POST");

      php code: (I also tried $_POST, $_GET, $_REQUEST. $HTTP_POSTVARS)
      <?php

      //mysql 4.1.2, php 4 , NO mysqli

      ecbo $_REQUEST ['testing'];
      /?>
        • 1. Re: Flash to PHP using LoadVars.send
          kglad Adobe Community Professional & MVP
          the send method is not reliable.

          create two loadvars instances and use one to send and the other to receive data back, even if nothing is coming back. then use the sendAndLoad method.

          use $_POST in your php when you use "POST" in your sendAndLoad parameter.
          • 2. Re: Flash to PHP using LoadVars.send
            akiva.kent Level 1
            Here's WHAT WORKS! THANKS kglad - I've also put a kudo to you on my splash screen.
            Hint: I had to make the php file write the contents of the variable to a file because it doesn'tdisplay on the screen with echo in order to see that the variable was passed from flash to php.

            Adobe document source: http://livedocs.adobe.com/flashlite/2/main/00000572.html

            //var submitListener:Object = new Object();
            //submitListener.click = function(evt:Object) {
            var result_lv:LoadVars = new LoadVars();
            /*
            result_lv.onLoad = function(success:Boolean) {

            if (success) {
            result_ta.text = " sent successfully!";
            } else {
            result_ta.text = "Error connecting to server.";
            }

            };
            */
            var send_lv:LoadVars = new LoadVars();
            send_lv.nme = "Testing server2";
            sending.text = send_lv.nme;
            send_lv.sendAndLoad("loadvars.php", result_lv, "POST");
            //};
            //submit_button.addEventListener("click", submitListener);

            <?php
            $contents = $_POST['nme'];
            echo $contents; //DOESN'T DISPLAY CONTENTS
            //open the file in write only mode - used to see the contents of the _POST variable sent by LoadVars
            $file = fopen('loadvars.txt','w');

            //write the contents
            fwrite($file, $contents);

            //close the file
            fclose($file);

            ?>
            • 3. Re: Flash to PHP using LoadVars.send
              kglad Adobe Community Professional & MVP
              you're welcome.

              your echo string is returned to result_lv. so, if you create an onData handler for result_lv you'll be able to use the src parameter to display $contents in your textfield, if you want.

              the onLoad handler is good when variable/value pairs are echo'd by your php script.

              if you try and use and onData and onLoad handlers, only the onData will execute.