Flash Contact Form in ActionScript 3
Posted by admin in ActionScript 3, Flash, Tutorials
This flash contact form is simply made in Adobe Flash CS3 ActionScript 3. Email validation is better than previous version in ActionScript 2. It sends the form field variables to PHP and loads the response variables back to Flash using URLVariables, URLLoader, and URLRequest classes. It will be very useful for you to use or adapt it for your Flash projects.





[...] Related Post: Flash Contact Form in ActionScript 3 [...]
how do i enter the email address to where i want the message to be sent?
Hi kick, please follow http://www.webdesignmo.com/blog/2008/05/26/as2-flash-contact-form for it.
I believe I’ve set everything up correctly, however, I get an error message saying (I’ll translate from German to English (roughly)):
Error: Error #2101: The URLVariables.decode() passed String must have a URL-coded String with Name/Value-pair.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at test4_fla::MainTimeline/submit()
What have I missed out?
Thanks,
-Hyper
^hyperbola.
This problem is usually caused by extra &. In AS3 there can’t be any & at the beginning or end of the string, and there can only be one in between each name/value pair.
Try stripping out the extra & with this:
static public function strip(urlEncoding:String):String{
var x=-1;
while((x = urlEncoding.indexOf(“&”, x+1))!= -1){
var y=x;
while(urlEncoding.charAt(++y)==”&”);
urlEncoding = urlEncoding.substring(0,x+1)+urlEncoding.substring(y);
}
if(urlEncoding.charAt(0)==”&”)urlEncoding = urlEncoding.substring(1);
if(urlEncoding.charAt(urlEncoding.length-1)==”&”)urlEncoding = urlEncoding.substring(0,urlEncoding.length-1);
return urlEncoding;
}
I actually went a step further and made a replacement class for URLVariables. I posted it @ http://www.actionscript.org/forums/showthread.php3?p=791377#post791377
Enjoy!
Dear webdesignmo team ,
You have very wonderful reply forms .. keep it up
Good Luck ,
Arjhun
Thanks That is very useful to me i am really very-2 Thankful to you
Sunil Sharma
I am urgetely need flash contact form so it will very usefull to me
Thanks Webdesignmo
Sunil sharma
Hi
Im new to actionscript so i may be doing something wrong but i have changed the reciever email to my email, uploaded the site to my server, when i test the contact form it says sending at the bottom but the doesnt do anything and i dont recieve an email?
Any help will be greatly appreciated
Regards
Tom
Hi guys, the form is great you did and it helps me a lot.
There is just one problem. It works great if I put the swf file like a separate page inside an index file, but if I put it inside another swf movie on the server you cannot put the words inside the box fields, on the other side, you can put them regulary on my desktop.
What can be the problem ?
Putting the source as an image sucks.
I only need 2 lines and I have to type them out instead of copy & paste.
It’s not user friendly however “cool” it might look.
-Ben
Mr-Yellow,
You may download the source file for copy and paste.
Thanks.
very nice… i’m going to try on my website. Thanks you
The download link goes to a template site.
i want to use this contact form but edit it because i want to make a reservation page for my website will it be easy to edit the code on this and if i edit the code will i need to edit the php file to
thank you for sharing the tutorial. I learned a lot through this. keep it up!
I actually want to create a whole new form for ppl to enrol in courses. Whats the easiest way to do it?
A simple form that is easy to understand and complete and send. I have the fom made already in html for my current site. basically want to copy paste it into the flash site.
Thanks.
Daniel
Just wanted to extend my thanks for your work online. I happen across your blog from time to time and fine it very helpful.
Regarding the use of images, rather than code for examples. Keep it up. Works great for me.
I will try it.
I can’t seem to find the download, link brings me to your site, but not anywhere that the files can be downloaded, any help please. thanks
I need some help… I think everything is on right place but when I click on send button message_status shows “Failed! Your message cannot sent” and I receive the message to my mail…
Any help would be most appreciated….
I am a total n00b at php who’s having the same problem as guja, except it doesn’t send the email to me. My server is set up to handle php, and I just don’t know what I’m doing wrong. Any pointers?
it works great with the basic for but when i change it to the auto responder it just says sending and never processes?
How can I get the auto responder to work?
thanks.
Hi,
who can tell me, how to fix the problem in the input text?
There doesn’t work other input languages after embed fonts.
I mean, I have: “input text” in the “contact message”, embed: Basic Latin, Latin Extended I, Latin Extended A and Extended B.
But, when I open the website, switch keybord language to Lithuanian and write, I get letters:
aceei uu+ (EN keyboard buttons 12345678=) instead of:
Ä…Äęėįšųūž.
If I paste the right letters it works, but the visitors will not find the double way.
Hello, seems like I have a little problem, probably just to tired to figure it out, but still getting “failed to send” message…
Somewhere I need to change something, but can’t seem to find it. Could you pls just tell me…
Hi,
everything seems fine, except i’m not receiving any email or confirmation??? is there something i should look for in the .php or .fla
I’m having the same problem as JP…my form will show that it sends, but I’m not receiving anything on the e.mail side. Very frustrating!!
Any suggestions would save me some sanity!!!
Hey,
I have put the code and everything into my site and it says that there are errors with all the code. It says it all can not be ‘loaded’?
Hi , Please I need some help!! I’m new to AS3, and I don’t know where I have to put this code:
“Try stripping out the extra & with this:
static public function strip(urlEncoding:String):String{
var x=-1;
while((x = urlEncoding.indexOf(â€&â€, x+1))!= -1){
var y=x;
while(urlEncoding.charAt(++y)==â€&â€);
urlEncoding = urlEncoding.substring(0,x+1)+urlEncoding.substring(y);
}
if(urlEncoding.charAt(0)==â€&â€)urlEncoding = urlEncoding.substring(1);
if(urlEncoding.charAt(urlEncoding.length-1)==â€&â€)urlEncoding = urlEncoding.substring(0,urlEncoding.length-1);
return urlEncoding;
}”
Thanks for your answer!
hello, i use the code that you guys used on the contact form, but i have a problem with it and i was hopeing that you can help, the problem is that wen i type in a correst e-mail on the e-mail inputbox the AS is not making the proper validation and it keeps sending me the message that i need to type in a valid e-mail, can any body help me im adding my code so you can see if i have any thing wrong with it taks.
nombre_contacto.text = email_contacto.text = asunto_contacto.text =
mensaje_contacto.text = mensaje_status.text = “”;
boton_enviar.addEventListener(MouseEvent.CLICK,enviar); // para boton de envia e-mail
boton_limpiar.addEventListener(MouseEvent.CLICK,limpiarforma); //para boton de limpiar forma
var timer:Timer;
var var_load:URLLoader=new URLLoader;
var URL_request:URLRequest=new URLRequest(“Cont_telecom.php”);
URL_request.method=URLRequestMethod.POST;
function enviar(e:MouseEvent):void
{
if(nombre_contacto.text==”" ||email_contacto.text==”" ||
asunto_contacto.text==”"||mensaje_contacto.text==”")
{
mensaje_status.text=”Por favor llene todos los campos.”;
}
else if(!validacion_email(email_contacto.text))
{
mensaje_status.text=”Por favor introdusca una dirección de correo valida.”;
}
else
{
mensaje_status.text=”Enviando su mensaje……….”;
var datos_email:String= “nombre=”+ nombre_contacto.text
+ “&email=”+ email_contacto.text + “&asunto=”+ asunto_contacto.text
+ “&mensaje=”+ mensaje_contacto.text;
var URL_vars:URLVariables=new URLVariables (datos_email);
URL_vars.dataFormat = URLLoaderDataFormat.TEXT;
URL_request.data=URL_vars;
var_load.load(URL_request);
var_load.addEventListener(Event.COMPLETE, recibir_respuesta);
}
}
function limpiarforma(e:MouseEvent):void
{
nombre_contacto.text = email_contacto.text = asunto_contacto.text =
mensaje_contacto.text = mensaje_status.text=”";
}
function validacion_email(s:String):Boolean
{
var p:RegExp=/(\W|[_.\-])+@((\W|-)+\.)+\W{2,4}+/;
var r:Object=p.exec(s);
if (r==null)
{
return false;
}
return true;
}
function recibir_respuesta(e:Event):void
{
var loader:URLLoader=URLLoader(e.target);
var email_status=new URLVariables(loader.data).succes;
if (email_status == “yes”)
{
mensaje_status.text= “Su mensaje a sido enviado”;
timer=new Timer(500);
timer.addEventListener(TimerEvent.TIMER, on_timer);
timer.start();
}
else
{
mensaje_status.text= “Su mensaje no pudo ser enviado”;
}
}
function on_timer(te:TimerEvent):void
{
if (timer.currentCount>=10)
{
nombre_contacto.text=email_contacto.text=asunto_contacto.text=
mensaje_contacto.text=mensaje_status.text=”";
timer.removeEventListener(TimerEvent.TIMER,on_timer);
}
}
This form works great for me, but I have one question about the focus of the text fields changing when I hit “tab” on the key board to get to the next text field.
I will start writing in the “name” text field, but when I hit tab on my keyboard to move to the next text field, it jumps the focus to a navigation button, rather than to the next text field. If I hit tab again, it doesn’t go anywhere – it’s like the focus jumps out of the form completely. Any advice on keeping the focus inside the form, so that users can tab through the text fields? Thanks!
Hi,
I’m thinking of using the flashmo_081 and I need your help in how do i change the contact us form so as it sends it’s emails to the address i specify.
I thought it was PHP but there is no .php file included in the zip file
Your help is greatly appreciated
Hi, Im very new doing flash websites, I used you template to create a website, and everything looks great, I added the contact form, did everything good, added the php file and didnt work. Called my hosting service and it doesnt support php but it does support asp. My question is, without messing up everything i have how can i create the asp file to be able to send the email. I used the template you have for contact form. Thanks
Hi Maiano,
You just need to search for sample ASP mail function and make send_email.asp file with the same concept applied in PHP.
Hi, was just wondering if there is a way of setting the keyboard language. Im in EnUK so my @ key is where US ” is. When typing in my form, it reverses them. Any ideas?
hi, i’m quite new to this. just wondering, do i need a web server/host to make this form work? i haven’t bought a domain or anything like that so when i test my flash file i can type in everything but receive nothing in my e-mail.
Hi there
I have just come across this site and have found it quite useful. I am new to all this but have to say that i am not a huge fan of using Flash, would I be able to use another program instead?
Hello, I have a little problem, probably just to tired to figure it out, but still getting “failed to send” message…
Somewhere I need to change something, but can’t seem to find it. Could you pls just tell me…
I am attempting to use flashmo_128_elegant. I alwasy get “message cannot be sent.”
The AS3 script is as follows:
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = “”;
send_button.addEventListener(MouseEvent.CLICK, submit);
reset_button.addEventListener(MouseEvent.CLICK, reset);
var timer:Timer;
var var_load:URLLoader = new URLLoader;
var URL_request:URLRequest = new URLRequest(“send_email2.php”);
trace(URL_request);
URL_request.method = URLRequestMethod.POST;
function submit(e:MouseEvent):void
{
trace(URL_request);
if( contact_name.text == “” || contact_email.text == “” ||
contact_subject.text == “” || contact_message.text == “” )
{
message_status.text = “Please fill up all text fields.”;
}
else if( !validate_email(contact_email.text) )
{
message_status.text = “Please enter the valid email address.”;
}
else
{
message_status.text = “sending…”;
var email_data:String = “name=” + contact_name.text
+ “&email=” + contact_email.text
+ “&subject=” + contact_subject.text
+ “&message=” + contact_message.text;
trace(email_data);
var URL_vars:URLVariables = new URLVariables(email_data);
URL_vars.dataFormat = URLLoaderDataFormat.TEXT;
trace(URL_vars);
URL_request.data = URL_vars;
var_load.load( URL_request );
var_load.addEventListener(Event.COMPLETE, receive_response );
}
}
function reset(e:MouseEvent):void
{
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = “”;
}
function validate_email(s:String):Boolean
{
var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var r:Object = p.exec(s);
if( r == null )
{
return false;
}
return true;
}
function receive_response(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
var email_status = new URLVariables(loader.data).success;
if( email_status == “yes” )
{
message_status.text = “Success! Your message was sent.”;
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, on_timer);
timer.start();
}
else
{
message_status.text = “Failed! Your message cannot sent.”;
}
}
function on_timer(te:TimerEvent):void
{
if( timer.currentCount >= 10 )
{
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = “”;
timer.removeEventListener(TimerEvent.TIMER, on_timer);
}
}
and the “send_email2.php” is as following:
Any help is really appreciated.
Hello: I;m using flashmo_146 Dark night and I always get this statement from the contact form saying that the message could not be sent. I need help please.
the download example doesnt look that is work
the example works! My fault! I dint enable the php for my domain!
hello i got a contact form on my website, but it delivers a mesage “fail, the message can not be send” how can i make it work? tnx for help
Hi, this is a great site! Thank you very much for your templates.
Now about this form, it works in English but I cant embed my native language (Russian). I can embed Russian to all your templates, but I can’t do it to this form. Could you provide me information about what I have to do? Thanks again
me again
Just in case, I can embed all the fields, but text what I receive is unreadable
I am working on the code and everything seems to work fine, but when I try and input the information into the fields after about 3-5 seconds it erases the data. I can not fill out the form as it keeps erasing everything before I have a chance to fill it out. Any thoughts or things to check would be greatly appreciated.
Hi Brett,
I think there is something wrong in the codes after you edited. The original file does not happen like this.
I am trying to get the auto response to work but I see there is no code in the AS in flash to send it. How can I incorporate this please.
Well done for the form it works great.
Scrap my last I got it to work I was stupid and cut a piece of code out. Really silly
Sorry