A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Passing variables from flash to php script - Please help!

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2

    Passing variables from flash to php script - Please help!

    Hey everyone. I was wondering if anyone could help me. I am using as2 to pass a variable from flash to my php and nothing is being passed! Here is the action script code that I put on my button:

    Actionscript Code:
    on (release)
    {
              amount.text=5;
              form1= new LoadVars();
              form1.amount= amount.text;
              form1.sendAndLoad("http://mywebpage.com/test.php",amount,"POST");
              }


    Now the amount of "5" is being inputted into a dynamic text field with the variable and instance name of amount (which, in the future, will be hidden ). This is working fine when clicking on the button. What I am trying to do, without success, is to get this value of "5" to my test.php and have it echoed and it's just not happening . This is my php script:

    Actionscript Code:
    <?php
     
    $form_inp= $_POST['amount'];
    if ($form_inp==''")
    {
    print "
    Nothing inputted <br>";
    }
    else
    {
    print "
    You have inputted: $form_inp";
    }
    ?>

    I'm getting "Nothing inputted" everytime.

    I've already tried the different routes for the amount.text such as:

    Actionscript Code:
    on (release)
    {
      amount.text=5;
      form1= new LoadVars();
      form1.amount= this.amount.text;
      form1.sendAndLoad("http://mywebpage.com/test.php",amount,"POST");
      }

    and

    Actionscript Code:
    on (release)
    {
      amount.text=5;
      form1= new LoadVars();
      form1.amount= this._parent.amount.text;
      form1.sendAndLoad("http://mywebpage.com/test.php",amount,"POST");
      }

    etc.........

    I've also tried changing the variable name in the sendAndLoad function from amount to form1 like this:

    Actionscript Code:
    on (release)
    {
      amount.text=5;
      form1= new LoadVars();
      form1.amount= amount.text;
      form1.sendAndLoad("http://mywebpage.com/test.php",form1,"POST");
      }

    and still nothing. Then I put the as right onto the button like this:

    Actionscript Code:
    var sendLV:LoadVars=new LoadVars();
    var receiveLV:LoadVars=new LoadVars();
     
    yourbutton.onRelease=function(){
              amount.text=5;
             sendLV.amount= amount.text;
              sendLV.sendAndLoad("http://mywebpage.com/test.php",receiveLV,"POST");
    }
     
    receiveLV.onData=function(src){
    trace(src);
    }

    Not working either.

    In my php file I even tried the GET instead of the POST and it still turns up nothing.

    Actionscript Code:
    <?php
     
    $form_inp= $_GET['monto'];
    if ($form_inp=='')
    {
    print "Nothing inputted <br>";
    }
    else
    {
    print "You have inputted: $form_inp";
    }
    ?>

    Then I changed my php to something simpler:

    Actionscript Code:
    <?php
    $amount= $_POST['amount'];
    echo "You have:" . $amount;
    ?>

    And, guess what? That's right.... Nothing!

    Extra info: I have put the .swf file and the .php file on the same level in the same folder on my server just to be sure and the amount.text dynamic text field and the button are on the same level in the .swf file.

    Can anyone shed some light on my situation.......... pretty please? I am at wits end!

    Thank you soooo much.

  2. #2
    Member
    Join Date
    Jul 2011
    Posts
    51
    Actionscript Code:
    btn.onRelease = function() {
        var loginResponse:LoadVars = new LoadVars();
        loginResponse.onLoad = function(success:Boolean) {
            if (success) {
                result_txt.text = this.result;

            } else {
                result_txt.text = "Error: Unable loading";
            }
        };
        var login:LoadVars = new LoadVars();
        login.amount =amount.text;
        login.sendAndLoad("http://localhost/Arion03/sendLoad.php",loginResponse,"POST");
    };


    PHP Code:
    <?php 
    $amount
    $_POST['amount']; 
    echo 
    "&result=You have:" $amount;
    ?>
    Put the absolute path or you can test with relative path link to the php file.



    Regards
    Last edited by FlexFlashApps; 02-16-2012 at 06:39 PM.
    FFA

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks for the response FFA. Tried doing what you perscribed but the variable is still not getting passed over. I think I have to think outside the box. Perhaps it's something else I am doing wrong besides the AS and the PHP.

    If you have some more advice, it is more than welcome!

    Thanks again.

  4. #4
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    What is your server config?

    In which environment are you working?

    The example of FFA looks fine to me. And in localhost its working. Are you running the swf file direct on Flash Player? Or from browser?


    You have to give these info to understand your situation better.



    arkitx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center