User Guide

212 Data binding classes (Flash Professional only)
CustomFormatter class (Flash
Professional only)
ActionScript Class Name mx.data.binding.CustomFormatter
The CustomFormatter class defines two methods,
format() and unformat(), that provide
the 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() and unformat() methods. You can then assign that class to a binding
between components either by creating a new Binding object with ActionScript (see “Binding
class (Flash Professional only)” on page 208), or by using the Bindings tab in the Component
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 Schema tab of the
Component inspector. However, in that case, the formatter is 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 “Sample
custom formatter” on page 212.
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.
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
value property) is bound to the current value of a
TextInput component (its
text property). The custom formatter class formats the current
numeric value of 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.
NOTE
To make this class available at runtime, you must include the data binding classes in your
FLA file.