Mike Chambers

code = joy

DRK 3 : TextField / DataValidation Example 1

with 6 comments

I have been getting some requests for some examples of the components included on DRK 3, so I am going to try and post a bunch over the coming days.

The first example is a simple one showing how to validate user input using the TextField component and Data Validation library.


And here is the code:

#include "com/macromedia/validation/DataValidation.as"

//set the function to be called when isValid is called.
//in this case it is the isDigit function from the DataValidation library
myTextField_txf.setValidationFunction("isDigit", DataValidation);

//set the default textfield icon to error.
myTextField_txf.setIcon("ftf_errorIcon");

//this is called when the validate button is pressed
validate_btn.onRelease = function()
{
	//call isValid to see if user input is valid.
	if(!myTextField_txf.isValid())
	{
		//if it is not, give an error and show the error icon.
		msgBox_txf.text = "Invalid Input. Please enter a number.";
		myTextField_txf.showIcon(true);
	}
	else
	{
		//if it is valid, make sure the icon is off.
		msgBox_txf.text = "The input is a valid number";
		myTextField_txf.showIcon(false);
	}
}

You can view the on-line docs for the TextField component here.

You can find more information about the Flash UI Component Set 5 (which includes the TextField component) here.

You can find more information about DRK 3 here.

Post any requests for specific examples in the comments.

Written by mikechambers

April 23rd, 2003 at 11:59 am

Posted in DRK

6 Responses to 'DRK 3 : TextField / DataValidation Example 1'

Subscribe to comments with RSS

  1. Try:
    2e

    Did I break it or what?

    Or, do you count ‘e’ like the natural log…?

    Phillip Kerman

    29 Apr 03 at 10:40 pm

  2. Okay, I’ll answer my own question. It appears to be a bug in Flash. Works fine in JavaScript (at least on IE Win).

    I don’t know how I found that one.

    Phillip

    Phillip Kerman

    30 Apr 03 at 11:20 pm

  3. maybe 2e stands for “2 elevated”. anyway I think this should be invalid.

    maxxxx

    7 May 03 at 11:55 am

  4. e is the exponent not natural log:

    2e3 = 2000
    2e4 = 20000
    etc.
    2e is the same as 2e0 which should evaluate to 2
    This is not a bug. The e is not a method, function, or constant. It is actually a part of the number itself. Think of the following analogy:
    “Can’t” is a word though it stands for “Cannot” – should we rule it out because it’s a contraction – no, of course not. 2e10 is a whole lot easier to write than 20000000000, and simply should not be excluded from this validation.

    Samuel Christie

    15 May 03 at 9:39 am

  5. To be a little more technical, e is actually not the exponent of the preceeding number. It is, as you can see from my example, the exponent of 10. As in the following:
    2e3 = 2*(10^3) = 2*1000 = 2000

    Just thought I’d correct myself.

    Samuel Christie

    15 May 03 at 9:42 am

  6. Geeze. It doesn’t work if I enter “pi” either.

    Anonymous

    21 May 03 at 5:31 pm

Leave a Reply