AS3 email form

Actionscript 3.0 questions.

AS3 email form

Postby bouboudo » Mon Apr 14, 2008 5:22 am

Hi! I have an email form with AS2 code that I used for years! Can someone help me convert the code to AS3? Here's the code:
Code: Select all
stop();
send_btn.onRelease = function() {
   my_vars = new LoadVars();
   my_vars.sender = email_box.text;
   my_vars.subject = subject_box.text;
   my_vars.message = message_box.text;
   if (my_vars.sender != "" and my_vars.subject != "" and my_vars.message != "") {
      my_vars.sendAndLoad("mailer.php", my_vars, "POST");
      gotoAndStop(2);
   } else {
      error_clip.gotoAndPlay(2);
   }
   my_vars.onLoad = function() {
      gotoAndStop(3);
   };
};
email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=function () {
   if (error_clip._currentframe != 1) {
      error_clip.gotoAndPlay(6);
   }
};
User avatar
bouboudo
 
Posts: 40
Joined: Thu Apr 10, 2008 3:22 am
Location: Montreal
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby James » Mon Apr 14, 2008 10:34 am

Just a quick rewrite - not tested, but should work:

Code: Select all
send_btn.addEventListener(MouseEvent.CLICK, sendClicked);
email_box.addEventListener(FocusEvent.FOCUS_IN, focused);
subject_box.addEventListener(FocusEvent.FOCUS_IN, focused);
message_box.addEventListener(FocusEvent.FOCUS_IN, focused);

function sendClicked(ev:MouseEvent):void {
   var req:URLRequest = new URLRequest("mail.php");
   var vars:URLVariables = new URLVariables();
   var loader:URLLoader = new URLLoader();
   
   vars.sender = email_box.text;
   vars.subject = subject_box.text;
   vars.message = message_box.text;
   
   req.method = URLRequestMethod.POST;
   req.data = vars;
   
   loader.dataFormat = URLLoaderDataFormat.VARIABLES;
   loader.addEventListener(Event.COMPLETE, sent);
    loader.addEventListener(IOErrorEvent.IO_ERROR, unableToSend);
   
   if (vars.sender != "" && vars.subject != "" && vars.message != "") {
      loader.load(req);
      gotoAndStop(2);
    } else {
      error_clip.gotoAndPlay(2);
    }
}

function sent(ev:Event):void {
   gotoAndStop(3);
}

function unableToSend(ev:IOErrorEvent):void {
   trace("Unable to reach php file.");
}

function focused(ev:FocusEvent):void {
   if(error_clip.currentFrame != 1) {
      error_clip.gotoAndPlay(6);
   }
}
Image
Image
Please consider donating to GTAL if you can. Click donate at the top-right of this page.
User avatar
James
Moderator
 
Posts: 406
Joined: Sat Oct 13, 2007 9:29 pm
Location: London, UK
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby bouboudo » Mon Apr 14, 2008 11:41 pm

Hi James! Thank you for your reply. I made the changes in the fla files. It doesn't give me any error, but when I upload the files to my server, it doesn't work. It goes to the second frame (processing) and it stays there forever. Mabye it's not communicating with the PHP I don't know, I suck at AS3.

Thanks a lot!
Attachments

form.fla [ 370 KiB | Viewed 7020 times ]

Last edited by bouboudo on Thu Jun 19, 2008 9:55 pm, edited 1 time in total.
User avatar
bouboudo
 
Posts: 40
Joined: Thu Apr 10, 2008 3:22 am
Location: Montreal
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby bouboudo » Tue Apr 15, 2008 4:05 am

I changed the code a bit, but still not working. Now when I click submit, it says that the message has been sent, but I don't receive it (The form is in french).

I also uploaded the fla files with the minor changes I made.
Attachments

form.fla [ 701.5 KiB | Viewed 7007 times ]

Last edited by bouboudo on Thu Jun 19, 2008 9:56 pm, edited 1 time in total.
User avatar
bouboudo
 
Posts: 40
Joined: Thu Apr 10, 2008 3:22 am
Location: Montreal
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby James » Tue Apr 15, 2008 1:14 pm

It looks like the code was correct origionally. What is the name of your php file? Could you post the PHP code?
Image
Image
Please consider donating to GTAL if you can. Click donate at the top-right of this page.
User avatar
James
Moderator
 
Posts: 406
Joined: Sat Oct 13, 2007 9:29 pm
Location: London, UK
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby bouboudo » Tue Apr 15, 2008 3:21 pm

of course, here it is!
Attachments
mailer.php.zip
(1.02 KiB) Downloaded 570 times
User avatar
bouboudo
 
Posts: 40
Joined: Thu Apr 10, 2008 3:22 am
Location: Montreal
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby James » Tue Apr 15, 2008 4:43 pm

The origional code looks fine to me, though I might be missing something. Are you sure that it is not just because you didn't change "mail.php" to "mailer.php" in the code?
Image
Image
Please consider donating to GTAL if you can. Click donate at the top-right of this page.
User avatar
James
Moderator
 
Posts: 406
Joined: Sat Oct 13, 2007 9:29 pm
Location: London, UK
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby bouboudo » Wed Apr 16, 2008 2:41 am

ok, I just took the original code you sent, make sure the PHP filename was "mailer.php". When you fill the form and click "send" (in french, "envoyer"), it stays at the "processing" window forever, it doesn't jump to the "complete" window, [u]but I do reveive the form via email.

Here's the AS3 code:
Code: Select all
stop();
send_btn.addEventListener(MouseEvent.CLICK, sendClicked);
email_box.addEventListener(FocusEvent.FOCUS_IN, focused);
subject_box.addEventListener(FocusEvent.FOCUS_IN, focused);
message_box.addEventListener(FocusEvent.FOCUS_IN, focused);

function sendClicked(ev:MouseEvent):void {
   var req:URLRequest = new URLRequest("mailer.php");
   var vars:URLVariables = new URLVariables();
   var loader:URLLoader = new URLLoader();
   
   vars.sender = email_box.text;
   vars.subject = subject_box.text;
   vars.message = message_box.text;
   
   
   req.method = URLRequestMethod.POST;
   req.data = vars;
   
   loader.dataFormat = URLLoaderDataFormat.VARIABLES;
   loader.addEventListener(Event.COMPLETE, sent);
    loader.addEventListener(IOErrorEvent.IO_ERROR, unableToSend);
   
   if (vars.sender != "" && vars.subject != "" && vars.message != "") {
      loader.load(req);
      gotoAndStop(2);
    } else {
      error_clip.gotoAndPlay(2);
    }
}

function sent(ev:Event):void {
   gotoAndStop(3);
}

function unableToSend(ev:IOErrorEvent):void {
   trace("Unable to reach php file.");
}

function focused(ev:FocusEvent):void {
   if(error_clip.currentFrame != 1) {
      error_clip.gotoAndPlay(6);
   }
}


Here's the PHP code:
Code: Select all
<?php

/* ---------------------------
php and flash contact form.
by www.MacromediaHelp.com
---------------------------
Note: most servers require that one of the emails (sender or receiver) to be an email hosted by same server,
so make sure your email (on last line of this file) is one hosted on same server.
--------------------------- */


// read the variables form the string, (this is not needed with some servers).
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
$sender = $_REQUEST["sender"];


// include sender IP in the message.
$full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $message;
$message= $full_message;

// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$sender = stripslashes($sender);

// add a prefix in the subject line so that you know the email was sent by online form
$subject = "Contact form ". $subject;

// send the email, make sure you replace email@yourserver.com with your email address
if(isset($message) and isset($subject) and isset($sender)){
   mail("form@dbpromedia.com", $subject, $message, "From: $sender");
}
?>

I attached a zip file that contain both fla and php files, mabye you'll find something! Thanks a lot.
Attachments
fla_php_files.zip
(535.45 KiB) Downloaded 726 times
Last edited by bouboudo on Thu Jun 19, 2008 9:57 pm, edited 1 time in total.
User avatar
bouboudo
 
Posts: 40
Joined: Thu Apr 10, 2008 3:22 am
Location: Montreal
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby James » Wed Apr 16, 2008 6:54 pm

Maybe Flash requires some output from PHP - though I doubt it. I will look over the code again, but in the mean time, try adding an output at the bottom of your PHP file.

Code: Select all
// send the email, make sure you replace email@yourserver.com with your email address
if(isset($message) and isset($subject) and isset($sender)){
   mail("form@dbpromedia.com", $subject, $message, "From: $sender");
   echo "SENT";
}
?>
Image
Image
Please consider donating to GTAL if you can. Click donate at the top-right of this page.
User avatar
James
Moderator
 
Posts: 406
Joined: Sat Oct 13, 2007 9:29 pm
Location: London, UK
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby bouboudo » Wed Apr 16, 2008 11:41 pm

Hi James, thanks a lot for your post. I did add the output at the bottom of the code but it's doing the same thing, freeze on frame 2 "processing". I'll wait to see if you find something!
Dominic.
User avatar
bouboudo
 
Posts: 40
Joined: Thu Apr 10, 2008 3:22 am
Location: Montreal
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby James » Thu Apr 17, 2008 4:36 pm

Try removing the line:

Code: Select all
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
Image
Image
Please consider donating to GTAL if you can. Click donate at the top-right of this page.
User avatar
James
Moderator
 
Posts: 406
Joined: Sat Oct 13, 2007 9:29 pm
Location: London, UK
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby bouboudo » Thu Apr 17, 2008 8:54 pm

WORKING! thanks a LOT!!! By the way, where did you get your AS3 skills???
Dominic
User avatar
bouboudo
 
Posts: 40
Joined: Thu Apr 10, 2008 3:22 am
Location: Montreal
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby tibi » Fri Apr 18, 2008 11:06 am

Also use POST variables in the php code instead of $_REQUEST...
I LOVE FLASH!!! --- http://www.webdesign-flash.ro/
FLASH FORUM ROMANIA --- http://www.flashforum.ro/
User avatar
tibi
 
Posts: 339
Joined: Sat Oct 13, 2007 12:03 pm
Location: HUNEDOARA -> ROMANIA
Flash Version: Adobe Flash CS5
Authoring Environment: Microsoft Windows

Re: AS3 email form

Postby James » Fri Apr 18, 2008 12:58 pm

I origionally learned AS2 from lynda.com, but AS3 mostly from books (Essential ActionScript 3.0 etc...), online, from the documentation, and from trying out my own ideas.
Image
Image
Please consider donating to GTAL if you can. Click donate at the top-right of this page.
User avatar
James
Moderator
 
Posts: 406
Joined: Sat Oct 13, 2007 9:29 pm
Location: London, UK
Flash Version: Adobe Flash CS5.5
Authoring Environment: Apple OS

Re: AS3 email form

Postby sankar22222 » Thu Nov 11, 2010 6:30 am

Hi guys i can't download the zip file it shows it's not existing
sankar22222
 
Posts: 3
Joined: Thu Jul 09, 2009 2:33 pm
Flash Version: Adobe Flash CS5

Next

Return to Actionscript 3.0

Who is online

Users browsing this forum: No registered users and 2 guests