Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 212

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

Advertisement

Handling errors with the SwitchSymbolFormatter
class
Unlike other formatters, the
into an
property. Instead, it is your responsibility to test for error conditions and return
error
an error message if appropriate.
The custom formatter component in the following example formats nine-digit Social Security
numbers by using the SwitchSymbolFormatter class:
package myFormatters
{
// formatters/myFormatter/CustomSSFormatter.as
import mx.formatters.Formatter
import mx.formatters.SwitchSymbolFormatter
public class CustomSSFormatter extends Formatter
{
// Declare the variable to hold the pattern string.
public var formatString : String = "###-##-####";
// Constructor
public function CustomSSFormatter() {
// Call base class constructor.
super();
}
// Override format().
override public function format( value:Object ):String {
// Validate input string value - must be a 9-digit number.
// You must explicitly check if the value is a number.
// The formatter does not do that for you.
if( !value
{
}
// Validate format string.
// It must contain 9 number placeholders.
var numCharCnt:int = 0;
for( var i:int = 0; i<formatString.length; i++ )
{
}
if( numCharCnt != 9 )
{
212
Creating Custom Formatters
SwitchSymbolFormatter
|| value.toString().length != 9)
error="Invalid String Length";
return ""
if( formatString.charAt(i) == "#" )
{
numCharCnt++;
}
class does not write its error messages

Advertisement

Table of Contents
loading

Table of Contents