Flash Script – Form Validation in Flash

Tweet


type = 'application/x-shockwave-flash'
data = 'http://sitepointstatic.com/flash/numcheck.swf'
width = '400'
height = '400'
bgcolor = 'black'
>

If you create a form for your site, you should, of course, check for errors in user input before the form can be successsfully submitted.

This simple tutorial will show you how to check whether a user-entered number is actually a number, not some other character. Download the sample files here.

1. Create an empty text box, and give it the variable name "txt".

2. Create a button of your choice, right click the button, and select "actions". Insert this action:

on (release) 
{
if(int(txt)==0)
{
txt="Not Number";
}
else
{
txt="Is Number";
}
}

3. That’s it! Now, take it for a spin! Enter a letter or number into your form, and see it function.

Here’s how it works. If any letter appears in text box, int() returns 0, otherwise, int returns the entered number. Simple!

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

No Reader comments