![]() | ![]() ![]() ![]() |
![]() | |
![]() | |
![]() |
A formatter is an object that performs bidirectional conversion of data between a raw data type and string data. The object has parameters that are settable during authoring, and runtime methods for doing the conversion. The number of formatters allowed is unlimited, and you can create additional custom formatters. Formatters are defined by XML files found in the Flash MX Professional 2004 Configuration/Formatters folder. The definition includes the following metadata:
The following formatters ship with Flash MX Professional 2004:
None The default formatter. No formatting is performed.
Boolean This formatter formats a Boolean value as a string. You can set up Boolean options for strings that mean true
(e.g., 1, yes, yup) and strings that mean false
(e.g., 0, no, nope).
Compose String This formatter converts a data object to a string. You define the output format using a string template. The template is arbitrary text that can refer to fields of the data as one of the following:
<field-name>
<field-name.field-name>
, using dots to drill down into the data structure<.>
, which represents the entire object. This can be used, for example, when the original object is a string, in which case <.>
is simply the value of the string.Custom Formatter This formatter allows you to specify your own formatter by specifying a class name. The formatter ActionScript class should have the following format:
class MyFormatter extends mx.data.binding.CustomFormatter{ function getTypedValue(requestedType: String) : mx.data.binding.TypedValue{ ... } function getGettableTypes() : Array /* of String */{ ... } function setTypedValue(newValue: mx.data.binding.TypedValue) : Array /* of String */{ ... } function getSettableTypes() : Array /* of String */{ ... } }
Rearrange Fields This formatter creates a new array of objects based on the original array in your binding. You define the fields on the new array by using a string template in the form:
fieldname1=definition1;fieldname2=definition2;and so on.
The fieldnameN
are the names of the fields in the new array or records. The definitionN
is one of the following:
For example, suppose you want to assign an array to the DataProvider
property of a List component using data binding. The objects within the array do not have a label
property (which the list uses if available). You could use this formatter to create a new array through data binding that replicates the objects within your original array and adds a label
property to each object using the values you define. The following template would achieve this (this would be on a binding between your array and the List component's DataProvider
property):
label='My name is <firstName> <lastName>'
This syntax assumes that the object has two properties, called firstName
and lastName
. The label
property will be added to each object within the new array.
Note: This formatter can be used with any component that accepts an array of records as a binding.
Number Formatter This formatter allows you to specify the number of fractional digits that appears when a number is converted to text.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |