Sunday, January 29, 2012

Input Textbox with default text in flash forms

Figured this out today(with help from Anoop and Bala),
Documenting it for future reference(coz i never remember this stuff).

How to make an Input Textbox with default text(in flash forms)
Simply creating an input text field in flash allows the user to type in stuff.. however if you wan't to add "default text" that will be visible until the visitor starts typing.. thats a different story..

here's how to do it:

1) Create your form artwork


2) Create a text field. Type in the text you want as the "default text".

make it an "input text" field in the properties panel
also remember to embed whatever non system font you plan on using.



3) Give the text field an instance name


4) Copy this code to an empty frame

txt_email.onSetFocus = function ()
{
if(this.text == "Type Your Name Here")
this.text = "";
};
txt_email.onKillFocus = function ()
{
if (this.text == "")
{
this.text = "Type Your Name Here";
} // end if
};


make sure your default text is exactly the same in the code(two locations) as well as in the text field

thats it.. should work now.
for more advanced tutorials(about the rest of the form, try this awesome site. this was just for my own reference in future projects.

No comments: