First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Jeffrey F. Hill | Website: http://www.flash-db.com

Part I - Setting up the Form in Flash

Begin setting up the Flash form by creating text fields that will contain the information that you want to send.  The most basic fields are the Name, E-mail, and Comments fields.  Create each text field that you want to use as an "Input Text" field.  Then give each one a unique name.  Set the Max Chars option to a number  you think should be the maximum number of characters allowed for each field.

To create hidden information that is passed to the script and eventually the e-mail,  all you have to do is set a variable.  For example you can set a unique Subject line in each e-mail you send by creating a variable named Subject. Another example would be if you wanted to set a different destination e-mail address for each occurrence of the form.  This is important if you want to be able to use the same exact form to be able to send different e-mails in different locations in the main Flash movie.  And then give it a value.  Here's an example:

Subject = "This is the Subject";
ToEmail = "joeBob@example.com";

These variables must be located on the same level in the same movie clip as the rest of the text fields.   Additionally, the button that will eventually call the script and send the information to your server and on to the specified e-mail, must reside at that same level. 

You can set up the form as either a separate movie clip located somewhere in the main movie or just on the _root level of the movie.  I would recommend setting it up as a self contained Movie clip so you could use it over and over in many different places in the movie - or in future projects.   To make everything easier, as mentioned earlier, try to keep all the text fields and hidden variables on the same level in the same Movie Clip.  This is however not necessary - you can use information, for example the e-mail address of the sender, from other parts of the script - you just have to get the paths right.  For example say you are sending the information from a movie clip called Mail and the user has already entered his/her e-mail in the main movie on the _root level.  You can automatically fill out the text field named E-mail by using the code Email = _root.Mail.Email; in the Movie Clip Mail.  Ok sounds confusing but it's really not, after a short time of messing around with it and trying different solutions you'll get it. 

We will now create a dynamic text field named EmailStatus.  This text field will be used to show messages to the user on the progress or status of their e-mail.  You can also use this text field to display eror messages to the user, for example if they did not fill out one of the fields or they are not using a valid e-mail address. 

For the next part of creating the form - create a button and label it SendMail or something similar.  Place this in the same Movie clip as the rest of your Input text Fields.  Then attach the following code to it:

on (release) {
    	if (!Email.length || Email.indexOf("@") == -1 || Email.indexOf(".") == -1) {
		EmailStatus = "Please enter a valid E-mail address";

	else if (!FirstName.length) {
		EmailStatus = "Please Enter your name before Sending";

	else if (!ToComments.length) {
		EmailStatus = "Please enter some text in you message";
	else {
		loadVariablesNum ("snowMailPHP.php", "0", "Post");
        EmailStatus = "Sending... one Moment .. or two.. sometimes it's faster then other times";

This code checks to make sure that all the input fields/variables have been filed out.  In the case of the Email, it checks to make sure that it is a valid e-mail address.  It checks for an @ symbol and a '.' symbol.  Hopefully by looking over the code you will be able to use this same method for any other input fields/variables you want to be sent to an e-mail address.  Note - this is not necessary, the only really important part of the above code is the "loadVariablesNum ("snowMailPHP.php", "0", "Post");" line.  Also note that this is the one line that you will have to change if you are going to be using something other then PHP to send the mail.  If you are using Perl, instead the line would read:  "loadVariablesNum ("http://www.yoursite.com/cgi-bin/snowMailPerl.cgi", "0", "Post");"  Or with ASP - "loadVariablesNum ("ASPMail.asp", "0", "Post");"

 Note: In the online example there are two extra fields named 'ToMail' and 'ToName' - These variables allow you to send an e-mail to anyone you want to.  Basically it's an anonymous e-mailer - There are a couple of precautions built in to discourage abuse of it in the actual example - but not in the attached downloadable documentation.  However you should not set up your Mail form in this way.   Always make the ToEmail hard coded into the script that you are using (or a hidden variable in the Mail Movie Clip). This will be shown later in this tutorial.   

That's all there is to the Flash part - now on to the exciting part - setting up the server side scripts. 

» Level Advanced

Added: 2001-08-27
Rating: 9 Votes: 328
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.