A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Using loadVariables method not working...

  1. #1
    Member
    Join Date
    Aug 2007
    Posts
    47

    Using loadVariables method not working...

    Hello there.
    I've inherited an elearning AS2 project from another designer which sends off an email at the end.
    The AS2 code uses the form.loadVariables(_root.submitURL, "POST") method to send variables (assigned to the object 'form') to the PHP.
    The PHP works when targetted directly, but not when variables are sent from Flash.
    The additionally odd thing is that the original flash file DID work. Has the loadVariables method been deprecated recently? I'm at a loss. Any help well appreciated.
    Cheers.

  2. #2
    Member
    Join Date
    Aug 2007
    Posts
    47
    OK, so it seems I should have done a bit more research before posting (I usually code in AS3). The loadVariables method has, indeed been deprecated. Now I just need to sort out how to get my LoadVars object sending variables without opening a browser window...

  3. #3
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    Check out sendAndLoad(). it's easy peasy
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  4. #4
    Member
    Join Date
    Aug 2007
    Posts
    47
    I did try sendAndLoad (to avoid the 'send' method opening a new browser window) at one point, but couldn't get it to work. I had 'echo's in the PHP sending variables back, with no luck and copied examples online. Went back to using just plain old send. Any more clues?
    Last edited by moosefetcher; 03-26-2011 at 06:04 AM.

  5. #5
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    Can you show the ode your using that doesn't work?
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  6. #6
    Member
    Join Date
    Aug 2007
    Posts
    47
    Thanks for the reply!
    Here's the PHP I was using (with echos toward the end)....

    Code:
    <?php
    $sendTo = "info@clientdomain.com";
    $subject = "TITLE OF PROJECT HERE";
    $name = strip_tags($_POST["name"]);
    $email = strip_tags($_POST["email"]);
    $region = strip_tags($_POST["region"]);
    $membership = strip_tags($_POST["membership"]);
    
    $headers = "From: " . $name . " <" . $email .">\r\n";
    $headers .= "Reply-To: " . $email . "\r\n";
    $headers .= "Return-path: " . $email;
    
    $message = "\r\nName: " . $name . "\r\nEmail: " . $email . "\r\nRegion: " . $region . "\r\nMembership number: " . $membership ."\r\n\r\n";
    
    
    mail($sendTo, $subject, $message, $headers); 
    
    echo(" $sendTo $name $email $region $subject<br>");
    
    echo(" $headers<br>");
    
    echo(" $message<br><br>");
    
    ?>
    And here's what I had happening in Flash...
    Code:
    var response:LoadVars = new LoadVars();
    response.onLoad = showResult;
    var form:LoadVars = new LoadVars();
    form.name = _root.user.data.name;
    //... various other variables (email, region and membership) added to 'form'...
    form.sendAndLoad(_root.submitURL, response,"POST");
    
    function showResult():Void{
    if (this.success) {
    	trace("server responded");
    } else {
    	trace("no server response");
    }
    }
    I usually code in AS3, so this was the part I couldn't quite follow. Why test the 'response' LoadVars instance for success? I think the trace always came back as 'no server response', but then the send method works fine (apart from loading a pointless new window in IE).
    Once again, any help well appreiciated.
    Cheers.

  7. #7
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    not sure why a new window is opening. Can't see any reason for it in the code. It maybe the fact that your echoing the $headers variable.
    you only need one var echoed after the mail send.
    php code:
    PHP Code:
    $ok mail($sendTo$subject$message$headers); 
    if(
    $ok){// if ok = true
    echo "&retval=1"//Email was sent
    }else{
    echo 
    "&retval=0"//Error sending email

    Flash code:
    code:

    if (this.success) {
    if(this.retval=="1"){
    trace("email sent");
    }else{
    trace("error sending email");
    }
    } else {
    trace("no server response");
    }



    hope it helps
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  8. #8
    Member
    Join Date
    Aug 2007
    Posts
    47
    OK, I've just read on another thread that for the sendAndLoad method the PHP needs to be on the same domain. This wasn't the case with what I was doing, but would the above set of code work if the PHP WAS on the same domain, or is there still something wrong with it?
    Cheers.

  9. #9
    Member
    Join Date
    Aug 2007
    Posts
    47
    Only just noticed your reply above, sorry.
    Just to be clear, I'm currently using the 'send' method and THAT opens a new window (I've read it's an AS2 bug). When using the 'send' method, I don't have the echos in the PHP anymore, but I would prefer to use the 'sendAndLoad' method as that doesn't open a new window, apparently.
    The flash code you've written is for the showResult function, right? If so, I'm not quite sure why you're setting retval on the 'response' LoadVars to 1. Isn't the 'response' LoadVars instance getting variables from the PHP?
    Thanks for the quick reply, BTW!

  10. #10
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    I am not setting the var in the response. I am checking the var.
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  11. #11
    Member
    Join Date
    Aug 2007
    Posts
    47
    Gah! I totally missed the PHP in your previous message! And I don't know why I saw that as SETTING the value in the AS. I must still be waking up. That makes sense.
    BUT - can I just check if the flash code that checks the value of retval should go in the showResult function... Does sendAndLoad need to get a response to be able to send?
    Once again, thanks for all the quick replies.

  12. #12
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    No but it does help the user by telling them that the form was submitted.
    I would never use sendAndLoad without checking that what i sent did actually send.
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  13. #13
    Member
    Join Date
    Aug 2007
    Posts
    47
    OK. Good to know. Once our own server has had some necessary SMTP change made, I'll give sendAndLoad another go.
    Cheers.

  14. #14
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    this should be
    Code:
    function showResult(success):Void{
    if (success) {
    	trace("server responded");
    } else {
    	trace("no server response");
    }
    }
    BTW: many mail servers say "ok" if a) there is enough room on the server disk to queue an outgoing mail and b) sending mail from php is not prohibited by administration.

    Musicman

  15. #15
    Member
    Join Date
    Aug 2007
    Posts
    47
    OK. Thanks!
    But then what should the boolean variable be that's passed to showResult?
    Cheers.

  16. #16
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    it indicates whether there was a result at all (as opposed to server not available at that very moment, misspelled url, etc)

    Musicman

  17. #17
    Member
    Join Date
    Aug 2007
    Posts
    47
    So the line...

    response.onLoad = showResult;

    ...still doesn't have to pass a variable to the function?

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