To validate text entered by a user in a TextInput component:
1.
Drag a TextInput component from the Components panel to the Stage, and name it
zipCode_txt.
2.
Select the TextInput component and, in the Component inspector, click the Schema tab.
3.
In the Schema Tree pane (the top pane of the Schema tab), select the
4.
In the Schema Attributes pane (the bottom pane of the Schema tab), select ZipCode from
the Data Type pop-up menu.
5.
Open the Timeline if it is not already open.
6.
Click the first frame on Layer 1 in the Timeline, and open the Actions panel (Window >
Actions).
7.
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);
8.
Select Window > Common Libraries > Classes to open the Classes library.
9.
Select Window > Library to open your document's library.
10.
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.
11.
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.
232
Data binding classes (Flash Professional only)
property.
text
Need help?
Do you have a question about the FLASH 8-COMPONENTS LANGUAGE and is the answer not in the manual?
Questions and answers