2007-05-03

Sending Email in Flash

Contact form is used widely on a website. If the website is powered by Flash, find a better way to build a flexible contact form is also very important.

There are probably 3 ways:

1. Use the "mailto:" protocol

Namely set a button event with

on (release) {
getURL("mailto:" + to + "?subject=" +subject+ "&body=" + body);
}
The three variables are self defined in Flash according to the form fields.  A tutorial can be found here.

The advantage of this method is that man doesn't need complex programming things. The flash will call the email client in the system to send the mail.

The shortcoming is also related to the advantage: If an email client isn't setup well or doesn't exist on the system, then we have a problem.

2. Use FLASH and PHP

It's used widely. So I don't want to talk more abut it. ;-) 

The principle is: Flash posts Variables to a PHP file, then the PHP sends email using mail() function and returns the result to flash.



A tutorial can be found at kirupa.com

3. Load a HTML into FLASH

The principle here is trying to load a html with contact form in Flash.

Firstly just use a textfield in Flash, set it to dynamic. Then click Render Text as HTML in properties or set the .html property to true. Then use Loadvars to load the html file and assign the variable into the textfield.htmlText property. Here's an example:
loadText = new LoadVars();
loadText.onLoad = function()
{
_root.helpText_txt.html = true;
_root.helpText_txt.htmlText = this.testText;
}
loadText.load("text.htm");
Just remember the following: You don't need all that header junk like tags and such. At the beginning of your html file, above everything else put something like:

testText =

where testText can be any variable name you choose. You can only use jpg and swf's for graphics embedded in the html. And the jpg's can't be progressive jpg's.

Finally anchors "<a href="http://www2.blogger.com/bla.html">" will work but won't show as a different color unless you use font tags around them and specify to change the color of the text. ie. "<span></a><a href="http://www.blogger.com/bla.html">Bla</a></span>"

More infos about "Formatting text with Cascading Style Sheets" can be found here.

P.S. According to this article, there are many ways to link a html in Flash.

No comments: