Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > Data binding classes > ComponentMixins.validateProperty() | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
componentInstance.validateProperty(propertyName)
propertyName A string that contains the name of a property that belongs to componentInstance.
An array, or null.
Method; determines if the data in propertyName is valid based on the property's schema settings. The property's schema settings are those specified on the Schema tab in the Component inspector.
The method returns null if the data is valid; otherwise, it returns an array of error messages as strings.
Validation applies only to fields that have schema information available. If a field is an object that contains other fields, each "child" field is validated, and so on, recursively. Each individual field dispatches a valid or invalid event, as necessary. For each data field contained by propertyName, this method dispatches valid or invalid events, as follows:
null, and is not required, the method returns null. No events are generated.null, and is required, an error is returned and an invalid event is generated.null and the field's schema does not have a validator, the method returns null; no events are generated.null and the field's schema does define a validator, the data is processed by the validator object. If the data is valid, a valid event is generated and null is returned; otherwise, an invalid event is generated and an array of error strings is returned.The following example shows how to use validateProperty() to make sure that text entered by a user is of a valid length. You'll determine the valid length by setting the Validation Options for the String data type in the Component inspector's Schema tab. If the user enters a string of invalid length in the text field, the error messages returned by validateProperty() are displayed in the Output panel.
text property.
// Add ComponentMixin methods to TextInput component.
// Note that this step is only necessary if the component
// isn't already involved in a data binding,
// either as the source or destination.
mx.data.binding.ComponentMixins.initComponent(zipCode_txt);
// Define event listener function for component:
validateResults = function (eventObj) {
var errors:Array = eventObj.target.validateProperty("text");
if (errors != null) {
trace(errors);
}
};
// Register listener function with component:
zipCode_txt.addEventListener("enter", validateResults);
This step makes the data binding runtime classes available to the SWF file at runtime. For more information, see Making data binding classes available at runtime.
In the TextInput component on the Stage, enter an invalid United States zip code--for example, one that contains all letters, or one that contains fewer than five numbers. Notice the error messages displayed in the Output panel.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002690.html