Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 221

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

}
return results;
}
}
}
This example first defines a public constructor that calls
its base class. The base class can perform the check to ensure that data was entered into a
required field, if you set the
Notice that the second argument of the constructor for the
use this argument to specify a subfield, if any, of the object being validated that caused the
error. When you are validating a single field, you can omit this argument. For an example that
validates multiple fields, see
You can use this validator in your Flex application, as the following example shows:
<?xml version="1.0" ?>
<!-- validators/MainAgeValidator.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myValidators.*">
<MyComp:AgeValidator id="ageV"
required="true"
source="{birthYear}"
property="text" />
<mx:Form >
<mx:FormItem label="Enter birth year: ">
<mx:TextInput id="birthYear"/>
</mx:FormItem>
<mx:FormItem label="Enter birth year: ">
<mx:Button label="Submit"/>
</mx:FormItem>
</mx:Form>
</mx:Application>
The
statement for your custom validator specifies that you should deploy it in a
package
directory called
myValidators
the directory that contains your Flex application. Therefore, the namespace definition in your
Flex application is
xmlns:MyComp="myValidators.*"
deployment, see
Chapter 6, "Compiling Components," on page
property of the validator to
required
"Example: Validating multiple fields" on page
. In the previous example, you place it in the subdirectory of
to invoke the constructor of
super()
.
true
ValidationResult
222.
. For more information on
63.
Example: Creating a simple validator
class is
. You
null
221

Advertisement

Table of Contents
loading

Table of Contents