Share on Google+Share on Google+

SwitchSymbolFormatter in FLex4

The SwitchSymbolFormatter Class is used for creating custom Formatters.

SwitchSymbolFormatter in Flex4:

The SwitchSymbolFormatter Class is used for creating custom Formatters. This Class is used for replacing placeholder characters in a string with another number string. In this example we useed SocialSecurityNumber for formatting. The format string is ###-##-#### and the input string is a nine digit number such as 345678934. After formatting the number will be shown like 345-67-8934. If an error occurs this error will be shown by the error property. The error property has two types of error values: Invalid value, Invalid format.
It is created by the action script. It has no component.


<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx=""



minWidth="955" minHeight="600" xmlns:local="*">



import mx.formatters.SwitchSymbolFormatter;


private var result:ValidationResultEvent;

private function checkFormat():void


result = scValidator.validate();

if (result.type==ValidationResultEvent.VALID) {

var temp:SwitchSymbolFormatter=new SwitchSymbolFormatter('#');

numlbl.text =temp.formatValue("###-##-####", numtxt.text);


else {

numlbl.text= "Invalid Number";






<mx:SocialSecurityValidator id="scValidator" source="{numtxt}" property="text"/>


<s:Panel title="SwitchSymbolFormatter Example" width="691">

<mx:Form backgroundColor="#096465" width="689">

<mx:FormItem label="Enter number with no Characters:" color="#FFFFFF"


<s:TextInput id="numtxt" text="" width="100%" maxChars="9" color="#000000"



<mx:FormItem label="Formatted Social Security Number:" color="#FFFFFF"


<s:Label id="numlbl" color="#FFFFFF" fontFamily="verdana"/>



<s:Button label="Format" click="checkFormat();"/>






Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

Download this code


Posted on: June 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null