Results 1 to 5 of 5

Thread: sendAndLoad does not return under flash

  1. #1
    Join Date
    Nov 2009
    Posts
    45

    sendAndLoad does not return under flash

    I have a little communication problem php -> flash.

    I have a SWF with 2 text fields that I have appointed vlogin and vpassword and a button named loginbutton

    I then send the information to the button with php script with this:

    HTML Code:
    loginButton.onRelease = function()
    {
    var a_send:LoadVars = new LoadVars();
    var a_receive:LoadVars = new LoadVars();
    a_receive.onLoad = function (success:Boolean)
    {
     if(success)
     {
      if (this.value == "bad" )
      {
       _root.gotoAndStop(3);//here the text field without a name with the variable value must show bad
      }
      else (this.value == "good" )
      {
       _root.gotoAndStop(2);//here the text field without a name with the variable value must display good
      }
     }
     else
     {
      _root.gotoAndStop(4);// msg:error 
     }
    };
    a_send.login = vlogin.text;
    a_send.password= vpassword.text;
    a_send.sendAndLoad("script.php", a_receive, "POST" );
    };
    my php page (tested with an HTML form) sent me the good news

    PHP Code:
    <?php
    include('connect.php');
    if(
    $_POST['login'])
    {
    $login = ($_POST['login']);
    $password = ($_POST['password']);
      
    $sql "select password from pwmaj where login='".$login."'";
      
    $req mysql_query($sql) or die('Error SQL !<br>'.$sql.'<br>'.mysql_error());
      
    $datamysql_fetch_assoc($req);
      if(
    $data['password'] != $password)
      {
       echo 
    "value=bad";
      }
      else
      {
    echo 
    "value=good";
      }
    }
    ?>
    The problem is that I didn't receive anything in flash and whatever happens good or bad login it pushes the return on the frame 2 that normally appears only if the return is "good" and its empty not good in the field ..

    no news for movie clip:
    Layer 1 img 1 field and button + script
    Layer 2 & 3 img 2 & 3 return field with var: value
    Layer 3 img 4 error message

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: sendAndLoad does not return under flash

    I think that PHP does not return what awaits in Flash ...

    Your code is wrong (it is because of the tolerance of AS2 what did not error), because you have half instead of else if else making it the default condition, so it can go over the important issues ...

    Otherwise, in PHP, use this syntax: echo "&value=good& "; // echo "&value=bad&";

  3. #3
    Join Date
    Nov 2008
    Posts
    996

    Re: sendAndLoad does not return under flash

    1. If you are not testing online, you need WAMP and call your PHP file so http://localhost/myfolder/script.php
    2. Your AI is very bad.

    You do not use _root and you have to populate your text fields by giving them a name occurrence with this syntax:
    myField_txt.text = myVar;

    This enables you to debug the code. You can test your code like this.
    You create a dynamic text field "DEBUG".
    Then:

    a_receive.onLoad = function (success:Boolean){
    if(success){
    DEBUG.text = this + " - my value : " + this.value;
    }
    }

  4. #4
    Join Date
    Nov 2009
    Posts
    45

    Re: sendAndLoad does not return under flash

    Thank you for the info with it I'm sure it's good!

    For AS I am coding only since last 2 weeks and flash has been a month since I use it and I'm not one to begin by reading the basic although I regret it often!

    Little question "You do not use _root" I should put anything to run the general scene instead of _root?

    And the "debug" I'll get more info I do not understand what has too matches the + or -

    And this + "- my_value" is the name of the variable that receives the variable in php?

  5. #5
    Join Date
    Nov 2008
    Posts
    996

    Re: sendAndLoad does not return under flash

    Little question "You do not use _root" I should put anything to run the general scene instead of _root?
    You can have a function like
    a_receive.onLoad = function (success:Boolean){
    if(success){
    treatSendAndLoad(this)
    }
    }

    function treatSendAndLoad(targ){
    trace(targ.value);
    }

    And the "debug" I'll get more info I do not understand what has too matches the + or -
    The debug is my way of naming debugging. It allows you to listen to what's happening in your code. You come variables in a text field to understand the results of operations.

    And this + "- my_value" is the name of the variable that receives the variable in php?
    While not all.

    At the beginning of your code, you write this
    var a_receive: LoadVars = new LoadVars ();
    and end
    a_send.sendAndLoad ( "script.php" a_receive, "POST");

    This means that the data returned by PHP will fit in the object "a_receive.
    When you do
    a_receive.onLoad = function (success: Boolean) {
    if (success) {
    DEBUG.text = this + "- my value:" + this.value;
    }
    }

    "this" is your subject "a_receive". By posting this (as here in a text field) you can see everything it contains. So sometimes the error messages from PHP, if you have sent for it coded.

    Moreover, this line
    DEBUG.text = this + "- my value:" + this.value;

    If you want to display the message "hello world", you'll do it this way
    trace("hello world" );

    If you want to display plus another thing (say a random number and size of your scene) syntax is this:
    trace("hello world " + Math.random() + Stage.width)

    It will give you something like "hello world 0.23365 640"

Similar Threads

  1. Can I return Ipad2 for new one?
    By Kaesav in forum Portable Devices
    Replies: 1
    Last Post: 13-03-2012, 06:48 PM
  2. Replies: 5
    Last Post: 25-06-2011, 05:58 AM
  3. SSH return function
    By Elizabeth Allen in forum Networking & Security
    Replies: 5
    Last Post: 22-04-2010, 02:38 PM
  4. How to use return() in PHP?
    By Leoniee in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 05:32 AM
  5. Replies: 6
    Last Post: 20-04-2007, 11:44 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,749,055.16203 seconds with 16 queries