Extending A Formatter Class - Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

Extending a Formatter class

You can extend the
Formatter
section shows an example that extends the
format pattern: "#####*####".
In this example, if the user omits a format string, or specifies the default value of
"#####*####", the formatter returns the ZIP code using the format "#####*####". If the
user specifies any other format string, such as a five-digit string in the form "#####", the
custom formatter calls the
format the data.
package myFormatters
{
// formatters/myFormatter/ExtendedZipCodeFormatter.as
import mx.formatters.Formatter
import mx.formatters.ZipCodeFormatter
import mx.formatters.SwitchSymbolFormatter
public class ExtendedZipCodeFormatter extends ZipCodeFormatter {
// Constructor
public function ExtendedZipCodeFormatter() {
// Call base class constructor.
super();
// Initialize formatString.
formatString = "#####*####";
}
// Override format().
override public function format(value:Object):String {
// 1. If the formatString is our new pattern,
// then validate and format it.
if( formatString == "#####*####" ){
if( String( value ).length == 5 )
if( String( value ).length == 9 ){
}
else {
}
214
Creating Custom Formatters
class to create a custom formatter, or any formatter class. This
ZipCodeFormatter
method in the superclass ZipCodeFormatter class to
format()
value = String( value ).concat("0000");
var dataFormatter:SwitchSymbolFormatter =
new SwitchSymbolFormatter();
return dataFormatter.formatValue( formatString, value );
error="Invalid String Length";
return ""
}
class by allowing an extra

Advertisement

Table of Contents
loading

Table of Contents