5 Replies Latest reply on Feb 12, 2007 3:19 AM by Peter Lorent

    Flash to Php and then back again

    Backen
      Hi
      I don't get it to work. I want to send and get information back from Php. And then i want to display the outpot in a dynamic textfield. I've seen a lot of tuts on this but it will not work for me. Here's my AS code

      var sender:LoadVars = new LoadVars
      var receive:LoadVars = new LoadVars

      receive.onLoad = function(success){
      if (success) {
      msgloggin.text = this.toFlash;
      } else {
      msgloggin.text = "failed";
      }}

      function submit( ) {
      sender.toPhp = "test";
      sender.sendAndLoad(" http://localhost/encrypted.php", receive, "POST");
      }

      btn.onRelease = submit;

      and the Php

      <?php

      $fromFlash = $_POST['toPhp'];
      $encrypted = md5($fromFlash);

      $toFlash = "&toFlash=";
      $toFlash .= $encrypted;

      echo $toFlash;
      ?>

      Is there anything i have missed or??
        • 1. Re: Flash to Php and then back again
          Level 7
          What is not working? Have you tried it online or locally only? Using $_POST
          in PHP won't work when you're testing locally from inside Flash - change to
          $_REQUEST for testing, and change back to $_POST when you put it on the
          server.

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


          • 2. Re: Flash to Php and then back again
            Level 7
            DMennenoh **AdobeCommunityExpert** wrote:
            > Using $_POST
            > in PHP won't work when you're testing locally from inside Flash - change to
            > $_REQUEST for testing, and change back to $_POST when you put it on the
            > server.

            Sorry, Dave, but that's complete nonsense. $_REQUEST is a synonym for
            $_POST and $_GET (and it's far less secure, so shouldn't be used).

            The problem with Backen's code is this:

            var sender:LoadVars = new LoadVars
            var receive:LoadVars = new LoadVars

            What's missing are the parentheses after LoadVars. It should be this:

            var sender:LoadVars = new LoadVars();
            var receive:LoadVars = new LoadVars();

            It then works - and yes, I've tested it locally.

            --
            David Powers, Adobe Community Expert
            Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
            Author, "PHP Solutions" (friends of ED)
            http://foundationphp.com/
            • 3. Re: Flash to Php and then back again
              Peter Lorent Level 2
              That is complete nonsense too because even without the parentheses the code will run...
              • 4. Re: Flash to Php and then back again
                Level 7
                LuigiL wrote:
                > That is complete nonsense too because even without the parentheses the code will run...

                Well, it's not total nonsense, because the parentheses should be there
                for completeness, but you're right - it does work without them, too.

                I've tested the OP's first set of code both with and without
                parentheses, and it works perfectly every time. The problem must lie
                elsewhere in the local setup. One possibility that should be
                investigated is whether a software firewall is preventing the server
                from communicating with Flash.

                --
                David Powers, Adobe Community Expert
                Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
                Author, "PHP Solutions" (friends of ED)
                http://foundationphp.com/
                • 5. Re: Flash to Php and then back again
                  Peter Lorent Level 2
                  Not total nonsense no but since you were reacting a bit overdone...
                  Well, there is something else wrong, you're right about that. Is msgloggin indeed the instance name of the text field or did he assign a var in the property inspector - in which case the code would fail.