Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 209

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

Advertisement

Creating a simple formatter
This example defines a simple formatter class that converts any string to all uppercase or all
lowercase letters depending on the value passed to the
formatter converts a String to all uppercase.
package myFormatters
{
// formatters/myFormatter/SimpleFormatter.as
import mx.formatters.Formatter
import mx.formatters.SwitchSymbolFormatter
public class SimpleFormatter extends Formatter
{
// Declare the variable to hold the pattern string.
public var myFormatString:String = "upper";
// Constructor
public function SimpleFormatter() {
// Call base class constructor.
super();
}
// Override format().
override public function format(value:Object):String {
// 1. Validate value - must be a nonzero length string.
if( value.length == 0)
{
}
// 2. If the value is valid, format the string.
switch (myFormatString) {
case "upper" :
case "lower" :
default :
}
}
}
}
error="0 Length String";
return ""
var upperString:String = value.toUpperCase();
return upperString;
break;
var lowerString:String = value.toLowerCase();
return lowerString;
break;
error="Invalid Format String";
return ""
property. By default, the
formatString
Creating a custom formatter
209

Advertisement

Table of Contents
loading

Table of Contents