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


Packagemx.formatters
Classpublic class ZipCodeFormatter
InheritanceZipCodeFormatter Inheritance Formatter Inheritance Object

The ZipCodeFormatter class formats a valid number into one of the following formats, based on a user-supplied formatString property.

A six-digit number must be supplied for a six-digit mask. If you use a five-digit or a nine-digit mask, you can use either a five-digit or a nine-digit number for formatting.

If an error occurs, an empty String is returned and a String that describes the error is saved to the error property. The error property can have one of the following values:

MXML Syntaxexpanded Hide MXML Syntax

The <mx:ZipCodeFormatter> tag inherits all of the tag attributes of its superclass, and adds the following tag attributes:

  <mx:ZipCodeFormatter
    formatString="#####|#####-####|### ###"
  />
  

View the examples.

See also

mx.formatters.SwitchSymbolFormatter


Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritederror : String
Description saved by the formatter when an error occurs.
Formatter
  formatString : String
The mask pattern.
ZipCodeFormatter
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Protected Properties
 PropertyDefined by
 InheriteddefaultInvalidFormatError : String = "Invalid format"
Error message for an invalid format string specified to the formatter.
Formatter
 InheriteddefaultInvalidValueError : String = "Invalid value"
Error message for an invalid value specified to the formatter.
Formatter
 InheritedpackageResources : ResourceBundle
[static] A ResourceBundle object containing all symbols from formatters.properties.
Formatter
Public Methods
 MethodDefined by
  
Constructor.
ZipCodeFormatter
  
Formats the String by using the specified format.
ZipCodeFormatter
 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
formatStringproperty
formatString:String  [read-write]

The mask pattern. Possible values are "#####-####", "##### ####", "#####", "###-###" and "### ###".

The default value is "#####".

Implementation
    public function get formatString():String
    public function set formatString(value:String):void
Constructor detail
ZipCodeFormatter()constructor
public function ZipCodeFormatter()

Constructor.

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

Formats the String by using the specified format. If the value cannot be formatted, return an empty String and write a description of the error to the error property.

Parameters
value:Object — Value to format.

Returns
String — Formatted String. Empty if an error occurs. A description of the error condition is written to the error property.
Examples
ZipCodeFormatterExample
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate ZipCodeFormatter. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

            import mx.events.ValidationResultEvent;            
            private var vResult:ValidationResultEvent;

            // Event handler to validate and format input.
            private function Format():void 
            {
                vResult = zcVal.validate();
                
                if (vResult.type==ValidationResultEvent.VALID) {
                    formattedZipcode.text= zipFormatter.format(zip.text);
                }
                
                else {
                    formattedZipcode.text= "";
                }
            }
        ]]>      
    </mx:Script>

    <mx:ZipCodeFormatter id="zipFormatter" formatString="#####-####"/>

    <mx:ZipCodeValidator id="zcVal" source="{zip}" property="text" allowedFormatChars=""/>

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

        <mx:Form width="100%">
            <mx:FormItem label="Enter a 5 or 9 digit U.S. ZIP code:" width="100%">
                <mx:TextInput id="zip" text=""/>
            </mx:FormItem>

            <mx:FormItem label="Formatted ZIP code: " width="100%">
                <mx:TextInput id="formattedZipcode" text="" editable="false"/>
            </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