Creating a custom formatter

You can create a custom formatter by creating a class that extends the mx.formatters. Formatter class or one of the standard formatters, which all extend mx.formatters.Formatter. Like the standard formatters, a custom formatter contains a public format() method that takes a value and returns a String. It might also contain a formatString property, depending on the type of value you want to format. This property provides a pattern that your formatted string will match. For example, the NumberFormatter and CurrencyFormatter classes do not have formatString properties, but the ZipCodeFormatter class does, because it formats its value based on a set pattern.

For all formatters, when an error occurs, an empty string is returned and a description is saved to an error property. The error property is inherited from the Formatter superclass.

To use a custom formatter component in an application, the component must be in the ActionScript classpath. For more information, see Creating ActionScript Components.

The examples in the following sections use the SwitchSymbolFormatter, which is a utility that takes numeric input strings and parses them through a set pattern. The pattern can contain any characters as long as they are constant for all values of the numeric portion of the string.


Version 1.5

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000739.htm