Adobe Flex 2 Language Reference - collected by Jimbob | Back to MY RESOURCES


Packagemx.formatters
Classpublic class Formatter
InheritanceFormatter Inheritance Object
SubclassesCurrencyFormatter, DateFormatter, NumberFormatter, PhoneFormatter, ZipCodeFormatter

The Formatter class is the base class for all data formatters. Any subclass of Formatter must override the format() method.

MXML Syntaxexpanded Hide MXML Syntax

The Formatter class defines the following tag attributes, which all of its subclasses inherit:

  <mx:tagname
    Properties
    error=""
  />
  

View the examples.



Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  error : String
Description saved by the formatter when an error occurs.
Formatter
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Protected Properties
 PropertyDefined by
  defaultInvalidFormatError : String = "Invalid format"
Error message for an invalid format string specified to the formatter.
Formatter
  defaultInvalidValueError : String = "Invalid value"
Error message for an invalid value specified to the formatter.
Formatter
  packageResources : ResourceBundle
[static] A ResourceBundle object containing all symbols from formatters.properties.
Formatter
Public Methods
 MethodDefined by
  
Constructor.
Formatter
  
Formats a value and returns a String containing the new, formatted, value.
Formatter
 Inherited
setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property detail
defaultInvalidFormatErrorproperty
protected var defaultInvalidFormatError:String = "Invalid format"

Error message for an invalid format string specified to the formatter.

The default value is "Invalid format".

defaultInvalidValueErrorproperty 
protected var defaultInvalidValueError:String = "Invalid value"

Error message for an invalid value specified to the formatter.

The default value is "Invalid value".

errorproperty 
public var error:String

Description saved by the formatter when an error occurs. For the possible values of this property, see the description of each formatter.

Subclasses must set this value in the format() method.

packageResourcesproperty 
protected static var packageResources:ResourceBundle

A ResourceBundle object containing all symbols from formatters.properties.

Constructor detail
Formatter()constructor
public function Formatter()

Constructor.

Method detail
format()method
public function format(value:Object):String

Formats a value and returns a String containing the new, formatted, value. All subclasses must override this method to implement the formatter.

Parameters
value:Object — Value to be formatted.

Returns
String — The formatted string.
Examples
SimpleFormatterExample
<?xml version="1.0"?>
<!-- Simple example to demonstrate the Formatter class. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

            // Event handler to format the input.            
            private function Format():void
            {
                // The format() method returns the formatted String,
                // or an empty String if there is an error.
                var formattedVal:String = numberFormatter.format(inputVal.text);

                if (formattedVal.length==0) {
                    // If there is an error, the Format.error property 
                    // contains the reason.
                    formattedNumber.text=numberFormatter.error;
                }
                
                else {
                    formattedNumber.text=formattedVal;
                }
            }
        ]]>
    </mx:Script>

    <mx:NumberFormatter id="numberFormatter"/>

    <mx:Panel title="NumberFormatter Example" width="75%" height="75%" 
            paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

        <mx:Form>
            <mx:FormItem label="Enter number - a letter is invalid:">
                <mx:TextInput id="inputVal" text="" width="75%"/>
            </mx:FormItem>

            <mx:FormItem label="Formatted number: ">
                <mx:TextInput id="formattedNumber" editable="false" width="75%"/>
            </mx:FormItem>

            <mx:FormItem>
                <mx:Button label="Validate and Format" click="Format();"/>
            </mx:FormItem>
        </mx:Form>
  
    </mx:Panel>
</mx:Application>





collected by Jimbob 2007.05