Her

Home Flash & Swish Flash Tutorials Macromedia Flash Email Actionscript Validation

Macromedia Flash Email Actionscript Validation

Author: CambodiaXP.com Author's URL: cambodiaxp.com More by this author

A form is a section of web document where users can enter data before submitting for processing. Usually, forms are misused by users if no proper validation control is in place. To prevent such abuse from happening one can make use the power of javascript to validate the form before sending it to the server.

Form in flash mx requires validation control as well. The good news is that it can be done using actionscript alone and this flash tutorial guide will show you how.

Here is what you are going to build today

To begin with, please download the partially done source code. This source code only contains the interface and I'll walk you through the process of making the flash email validation control works.

I assume you have downloaded the flash source code above and ready to begin.

1. Observe that we have 4 layers. The top layer name 'action' is what important to us and we are going to type in our flash actionscript there.

image 1

2. We have one input text box for user to type in and we give it an instance name 'email'.

image 2

3. Another dynamic text box for displaying the status of the validation and we name it 'message'.

image 3

4. On the bottom of the working space we have a button instance named 'validate_btn'.

Macromedia Flash Email Actionscript Validation

5. Okay, let's insert the real action into the action layer. First open up the first frame on the action layer and paste these codes into the action panel.

validate_btn.onRelease = function() {
indexOfAt = email.text.indexOf("@");
lastIndexOfDot = email.text.lastIndexOf(".");
if (indexOfAt !=-1 && lastIndexOfDot !=-1){
if (lastIndexOfDot <indexOfAt) {
message.text="please verify your email.";
}else {
message.text="Your email seems okay";
}
} else {
message.text="please enter correct email address";
}
}

6. Don't worry about the syntax first, just go on and test the movie by pressing 'CTRL+ENTER'.

Bingo!! You have just created an email validation control purely on actionscript!

And here is the full source code.