Add the following code to the Actions panel:
7.
// 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);
Select Window > Other Panels > Common Libraries > Classes to open the Classes library.
8.
Open your document's library by choosing Window > Library.
9.
Drag DataBindingClasses from the Classes library to your document's library.
10.
This step makes the data binding runtime classes available to the SWF file at runtime.
Test the SWF file by selecting Control > Test Movie.
11.
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.
DataType class (Flash Professional only)
ActionScript Class Name
The DataType class provides read and write access to data fields of a component property. To get
a DataType object, you call the
can then call methods of the DataType object to get and set the value of the field.
If you get and set field values directly on the component instance instead of using DataType class
methods, the data is provided in its "raw" form. In contrast, when you get or set field values using
DataType methods, the values are processed according to the field's schema settings.
For example, the following code gets the value of a component's property directly and assigns it to
a variable. The variable,
property
propName
var propVar = myComponent.propName;
The next example gets the value of the same property by using the
method. In this case, the value assigned to
processed according to its schema settings, and then returned as a string.
var dataTypeObj:mx.data.binding.DataType = myComponent.getField("propName");
var stringVar: String = dataTypeObj.getAsString();
For more information about how to specify a field's schema settings, see "Working with schemas
in the Schema tab (Flash Professional only)" in Using Flash.
234
Chapter 6: Components Dictionary
mx.data.binding.DataType
ComponentMixins.getField()
, contains whatever "raw" value is the current value of the
propVar
.
is the value of
stringVar
method on a component. You
DataType.getAsString()
after being
propName
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?