FORUMS: list search recent posts

Adding an e-mail flash form to my flash site

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Andrew Johnston
Adding an e-mail flash form to my flash site
on Apr 5, 2009 at 1:26:17 am

I have searched everywhere for a tutorial for this:

I am trying to add a form on my flash site that a user can fill out, click send, and it will send me all the data through e-mail. I don't need the e-mail sent to me to have a reply address of the person sending it or anything fancy like that... if just the info in the form was sent to me then I can work from there I'd be fine.

Also. One of the parts of the form I'd like to be a multiple choice text box and when all the info is sent to me I'll know what the user selected for that category.



Return to posts index

Pieter Helsen
Re: Adding an e-mail flash form to my flash site
on Apr 5, 2009 at 10:59:41 am

THIS IS AN AS3 EXAMPLE

Drag a checkbox component (Window > Components I think) onto the stage and give it an instance name. (like checkBox)

Then use the textfield tool to draw the fields that you need and again, give them an appropriate instance name. In my example, I'll use name_txt and msg_txt.

Then draw a button that will act as send button. Press F8 to 'Convert to Symbol'. Check MovieClip (you could work with a Button instead of a MovieClip, but I like working with MovieClips better.) Give the button another instance name in the properties panel. Like send_mc.

Next, put this actionscript onto the main timeline where you placed your form:


import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.net.navigateToURL;

// Add an eventlistener that will respond when the user clicks the send button
send_mc.addEventListener(MouseEvent.CLICK, mouseClickHandler);

// This function is called when the user clicks the send button
function mouseClickHandler(evt:MouseEvent):void {
// Retrieve the values from the textfields and checkbox
var name:String = name_txt.text;
var message:String = msg_txt.text;
var check:string = getCheckBox();

// Create a URLVariables object and store the variables to be sent to your PHP script
var vars:URLVariables = new URLVariables();
vars.name = name;
vars.message = message;
vars.check = check;

var request:URLRequest = new URLRequest();
request.data = vars;
request.method = URLRequestMethod.POST;
request.url = "myUrl.php" // ENTER YOUR WEBSITE HERE

navigateToURL(request);
}

// Checks if your checkbox is checked and returns a string
// When checked, "Selected" is returned else "Not selected" is returned
function getCheckBox():String {
if(checkBox.selected == true){
return "selected";
}else{
return "not selected";
}
}


This code sends all the variables to your PHP script using the POST method. So in your PHP script you would use $_POST['name'] and $_POST['check'] to get the variables. Now you just have to send the e-mail.

Good luck.

Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index

Andrew Johnston
Re: Adding an e-mail flash form to my flash site
on Apr 5, 2009 at 4:23:39 pm

Very cool, thank you. I'm going to try this when i get back to my computer later. Just a question though, My entire site was built using AS2. Will I be able to implement this AS3 code?


Return to posts index


Pieter Helsen
Re: Adding an e-mail flash form to my flash site
on Apr 5, 2009 at 4:28:40 pm

No.

For AS2, have a look at LoadVars.send()

Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]