CustomFormatter class (Flash Professional only)
ActionScript Class Name
The CustomFormatter class defines two methods,
ability to transform data values from a specific data type to String, and vice versa. By default, these
methods do nothing; you must implement them in a subclass of
mx.data.binding.CustomFormatter.
To create your own custom formatter, you first create a subclass of CustomFormatter that
implements
format()
between components either by creating a new Binding object with ActionScript (see
class (Flash Professional only)" on page
inspector. For information on assigning a formatter class using the Component inspector, see
"Schema formatters" in Using Flash.
You can also assign a formatter class to a component property on the Component inspector's
Schema tab. However, in that case, the formatter will be used only when the data is needed in the
form of a string. In contrast, formatters assigned with the Bindings panel, or created with
ActionScript, are used whenever when the binding is executed.
For an example of writing and assigning a custom formatter using ActionScript, see
custom formatter" on page
Note: To make this class available at runtime, you must include the data binding classes in your FLA
document.
For an overview of the classes in the mx.data.binding package, see
package (Flash Professional only)" on page
Sample custom formatter
The following example demonstrates how to create a custom formatter class and then apply it to a
binding between two components by using ActionScript. In this example, the current value of a
NumericStepper component (its
component (its
text
the NumericStepper component (for example, 1, 2, or 3) as its English word equivalent (for
example, "one", "two", or "three") before assigning it to the TextInput component.
To create and use a custom formatter:
In Flash MX Professional 2004, create a new ActionScript file.
1.
Add the following code to the file:
2.
// NumberFormatter.as
class NumberFormatter extends mx.data.binding.CustomFormatter {
// Format a Number, return a String
function format(rawValue) {
var returnValue;
var strArray = new Array('one', 'two', 'three');
var numArray = new Array(1, 2, 3);
returnValue = 0;
for (var i = 0; i<strArray.length; i++) {
mx.data.binding.CustomFormatter
and
methods. You can then assign that class to a binding
unformat()
214), or by using the Bindings tab in the Component
217.
213.
property) is bound to the current value of a TextInput
value
property). The custom formatter class formats the current numeric value of
and
format()
unformat()
"Classes in the mx.data.binding
Data binding classes (Flash Professional only)
, that provide the
"Binding
"Sample
217
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?
Questions and answers