User Guide

DataType class (Flash Professional only) 233
DataType class (Flash Professional only)
ActionScript Class Name mx.data.binding.DataType
The DataType class provides read and write access to data fields of a component property. To
get a DataType object, you call the
ComponentMixins.getField() method on a component.
You 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,
propVar, contains whatever “raw” value is the current value of
the property
propName.
var propVar = myComponent.propName;
The next example gets the value of the same property by using the DataType.getAsString()
method. In this case, the value assigned to
stringVar is the value of propName after being
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.
You can also use the methods of the DataType class to get or set fields in various data types.
The DataType class automatically converts the raw data to the requested type, if possible. For
example, in the code example above, the data that’s retrieved is converted to the String type,
even if the raw data is a different type.
The
ComponentMixins.getField() method is available for components that have been
included in a data binding (either as a source, destination, or an index), or that have been
initialized with
ComponentMixins.initComponent(). For more information, see
“ComponentMixins class (Flash Professional only)” on page 226.
For an overview of the classes in the mx.data.binding package, see “Classes in the
mx.data.binding package (Flash Professional only)” on page 208.
NOTE
To make this class available at runtime, you must include the data binding classes in your
FLA file.