Adobe® Flex® 4 Language Reference
Show Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
mx.formatters 
SwitchSymbolFormatter 
Packagemx.formatters
Classpublic class SwitchSymbolFormatter
InheritanceSwitchSymbolFormatter Inheritance Object

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

The SwitchSymbolFormatter class is a utility class that you can use when creating custom formatters. This class performs a substitution by replacing placeholder characters in one String with numbers from a second String.

For example, you specify the following information to the SwitchSymbolFormatter class:

Format String: "The SocialSecurity number is: ###-##-####"

Input String: "123456789"

The SwitchSymbolFormatter class parses the format String and replaces each placeholder character, by default the number character (#), with a number from the input String in the order in which the numbers are specified in the input String. You can define a different placeholder symbol by passing it to the constructor when you instantiate a SwitchSymbolFormatter object.

The output String created by the SwitchSymbolFormatter class from these two Strings is the following:

"The SocialSecurity number is: 123-45-6789"

The pattern can contain any characters as long as they are constant for all values of the numeric portion of the String. However, the value for formatting must be numeric.

The number of digits supplied in the source value must match the number of digits defined in the pattern String. This is the responsibility of the script calling the SwitchSymbolFormatter object.

View the examples

See also



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined By
  
SwitchSymbolFormatter(numberSymbol:String = "#")
Constructor.
SwitchSymbolFormatter
  
Creates a new String by formatting the source String using the format pattern.
SwitchSymbolFormatter
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Constructor Detail

SwitchSymbolFormatter

()Constructor
public function SwitchSymbolFormatter(numberSymbol:String = "#")

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Constructor.

Parameters
numberSymbol:String (default = "#") — Character to use as the pattern character.
Method Detail

formatValue

()method
public function formatValue(format:String, source:Object):String

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Creates a new String by formatting the source String using the format pattern.

Parameters

format:String — String that defines the user-requested pattern including.
 
source:Object — Valid number sequence (alpha characters are allowed if needed).

Returns
String
SwitchSymbolFormatterExample.mxml
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate SwitchSymbolFormatter. -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            import mx.formatters.SwitchSymbolFormatter;
            import mx.events.ValidationResultEvent;

            private var vResult:ValidationResultEvent;

            // Event handler to validate and format input.
            private function Format():void {
                vResult = scVal.validate();

                if (vResult.type == ValidationResultEvent.VALID) {
                    var switcher:SwitchSymbolFormatter = new SwitchSymbolFormatter('#');
                    formattedSCNumber.text = switcher.formatValue("Formatted Social Securty number: ###-##-#### ", scNum.text);
                } else {
                    formattedSCNumber.text= "";
                }
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <mx:SocialSecurityValidator id="scVal" source="{scNum}" property="text"/>
    </fx:Declarations>

    <s:Panel title="SwitchSymbolFormatter Example"
            width="75%" height="75%"
            horizontalCenter="0" verticalCenter="0">
        <s:VGroup left="10" right="10" top="10" bottom="10">
            <s:Label text="Enter a 9 digit Social Security number with no separator characters:" />
            <s:TextInput id="scNum" text="" maxChars="9" width="50%" />

            <s:Button label="Validate and Format" click="Format();" />
            <s:TextInput id="formattedSCNumber" editable="false" width="75%" />
        </s:VGroup>
    </s:Panel>

</s:Application>