ComponentMixins.validateProperty()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

componentInstance.validateProperty(propertyName)

Parameters

propertyName A string that contains the name of a property that belongs to componentInstance.

Returns

An array, or null.

Description

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:

Example

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.

To validate text entered by a user in a TextInput component:

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Drag a TextInput component from the Components panel to the Stage, and name it zipCode_txt.
  3. Select the TextInput component and, in the Component inspector, click the Schema tab.
  4. In the Schema Tree pane (the top pane of the Schema tab), select the text property.
  5. In the Schema Attributes pane (the bottom pane of the Schema tab), select ZipCode from the Data Type pop-up menu.
  6. Open the Timeline if it is not already open.
  7. Click the first frame on Layer 1 in the Timeline, and open the Actions panel (Window >  Actions).
  8. Add the following code to the Actions panel:
    // 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);
    
  9. Select Window > Common Libraries > Classes to open the Classes library.
  10. Select Window > Library to open your document's library.
  11. Drag DataBindingClasses from the Classes library to your document's library.

    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.

  12. Test the SWF file by selecting Control > Test Movie.

    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