sign up!

Are you interested in learning, then sign up to be notified about new tutorials.


helpfull links

website solutions

Do you need a website?
We can have you online in 24 hrs for less then $100

master flash

Are you looking to learn flash? If so you need to check out Flash, the Information you need. You will find all of these tutorials, source files and more...

Get your copy today!

Flash, This Information you need

a few friends

follow Us On

FrenchSquared on Linked in

FrenchSquared on Twitter

Frenchsquared on Facebook

Flash Tutorial, Contact Form

Flash Contact Form, What professional looking website doesn’t have a great contact form. I mean lets face it a simple mailto link is second rate. But how does one create an email form in flash? This tutorial will teach you the proper way to create a great email form.

If you use the code provided in this Flash Tutorial you will find that the headers of you email are properly formatted. That means the your email will actual say the name of an email not just some strange ip address. Better yet your headers are properly formatted so you can simply click the reply button.

For an added bonus if you purchase the source code you will receive the source files for an email form that lets you specify the sender as well as the receiver. See below.

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

The ActionScript

Create a variable for the visitors email.

var validmail:uint = 0;

Flash cannot send an email on its own so you are going to need some php. Before we go over the php we need to get the flash done. For now, copy the code below into the first actions keyframe. This code creates several variables that are going to be used to pass data to the php emailer.

var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("sendEmail.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST; = variables;

Add the event listener to make the submit button actually do something. Then add an event listener that does something when the data is pulled from the php emailer.

submit_btn.addEventListener (MouseEvent.CLICK, sendActions);
varLoader.addEventListener (Event.COMPLETE, loadComplete);

Ok, so lets make the text filed more useful by passing a set of parameters. A parameter is a quantity or value that defines a certain characteristic of the function. It will make scene as we continue. Return to the actions panel and modify the text already in-place. See Example

function textArea(parameter:String){

var myText:TextField = new TextField();
myText.text = parameter;

textArea("this is a parameter");

This next bit of code looks intense so just take you time and work through it. This is the function for the send button. It isn’t that intense it just checks to see if the is a correct email before sending the variable to the php emailer.

function sendActions (event:MouseEvent):void{
            if ((fname_txt.text != "" || subject_txt.text != "Required")
                        && email_txt.text != "" && (subject_txt.text != "" || subject_txt.text != "Required") ) {
                        // Check to make sure the email address includes and @.
                        var textLength:Number = email_txt.text.length;
                        for (var i:Number = 0; i < textLength; i++) {
                                    if (email_txt.text.substr(i, 1) == "@") {
                                                this.validmail = 1;
            if (this.validmail == 0) {
                        this.gotoAndStop ("error");
            } else {
                        variables.key = "pass"; //security code
                        variables.subject = subject_txt.text;
                        variables.fname = fname_txt.text;
               = email_txt.text;
                        variables.comments = comments_txt.text;
                        varLoader.load (varSend);

The important part are these variables:
variables.key = "pass";
variables.subject = subject_txt.text;
variables.fname = fname_txt.text; = email_txt.text;
variables.comments = comments_txt.text;
varLoader.load (varSend);

Each of the variables.XXXX has to match a post function in the email form and has to be set to a input field in your flash file. Key is defined as pass, this is simply so some other website can not target your php script. It is alway best to practice safe code.

You need to create another function for the loadComplete listner you created earlier. This function is going to take the variables you just assigned and add them to a var called loader, which is a URLLoader and then pass the variables to the php emailer

function loadComplete (event:Event)
            var loader:URLLoader = URLLoader(;
            trace ("completeHandler: " +;
                        if ( != "&reply=error") {
            //if (vars.reply != "error") {
                        this.gotoAndStop ("success");
            } else {
                        this.gotoAndStop ("error");
fname_txt.tabIndex = 2;
subject_txt.tabIndex = 3;
email_txt.tabIndex = 4;
comments_txt.tabIndex = 5;
submit_btn.tabIndex = 6;
this.stop ();

That is all that is required for Flash to send the email to the php page.


This isn’t a php tutorial so I will simply give you the php code. This code needs to be pasted into a new php file called sendEmail.php. It is the php that actually does the work.

            if(isset($_POST['fname'])){$fname = stripslashes($_POST['fname']);}
    else {$error .= "Your Name seems to be missing!";}
            if(isset($_POST['subject'])){$subject = stripslashes($_POST['subject']);}
    else {$error .= "your subject seems to be missing!";}
            if(isset($_POST['email'])){$email = stripslashes($_POST['email']);}
    else {$error .= "your email seems to be missing!";}
            if(isset($_POST['comments'])){$comments = stripslashes($_POST['comments']);}
    else {$error .= "The comments of your email seems to be missing!";}


if ($_POST['key'] == "pass") {
            $to = "";
            $subject = "{$_POST['subject']}";
            $message = "Sent From
            if ($_POST['comments'] != "") {
                        $message .= "
{$_POST['fname']} had the following comments:

            $headers = "";
            $headers .= "From: " . $_POST['fname'] . " <" . $_POST['email'] . ">\n";
            $headers .= "Reply-To: " . $_POST['fname'] . " <" . $_POST['email'] . ">\n";
            $headers .= "X-Mailer: PHP4\n" ; // mailer
            $headers .= "X-Priority: 3\n" ;  // priority
            $headers .= "Return-Path:  $to\n";
            $headers .= "Origin: ".$_SERVER['REMOTE_ADDR']."\n";
            $headers .= "Content-Type: text/plain; charset=us-ascii\n";

            if (mail($to,$subject,$message,$headers)) {
                        echo "&reply=success";
            } else {
                        echo "&reply=error";

Download Tutorials