Flash 8 Documentation |
|||
| Components Language Reference > Data binding classes (Flash Professional only) > 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).
|
NOTE |
|
To make this class available at runtime, you must include the data binding classes in your FLA file. For more information, see Making data binding classes available at runtime (Flash Professional only). |
For an overview of the classes in the mx.data.binding package, see Classes in the mx.data.binding package (Flash Professional only).
The following table lists the methods of the DataType class.
|
Method |
Description |
|---|---|
|
Fetches the current value of the field. |
|
|
Fetches the current value of the field as a Boolean value. |
|
|
Fetches the current value of the field as a number. |
|
|
Fetches the current value of the field as a String value. |
|
|
Fetches the current value of the field in the form of the requested data type. |
|
|
Sets a new value in the field. |
|
|
Sets the field to the new value, which is given as a Boolean value. |
|
|
Sets the field to the new value, which is given as a number. |
|
|
Sets the field to the new value, which is given as a string. |
|
|
Sets a new value in the field. |
The following table lists the properties of the DataType class.
|
Property |
Description |
|---|---|
|
Provides a reference to the encoder object associated with this field. |
|
|
Provides a reference to the formatter object associated with this field. |
|
|
Provides a reference to the Kind object associated with this field. |
Version 8
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/8/main/00003227.html