Home Tutorial Flex Flex4 Components SwitchSymbolFormatter in FLex4

 
 

SwitchSymbolFormatter in FLex4
Posted on: June 3, 2010 at 12:00 AM
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.

Example:

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

<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"

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

<fx:Script>

<![CDATA[

import mx.formatters.SwitchSymbolFormatter;

import mx.events.ValidationResultEvent;

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";

}

}

]]>

</fx:Script>

<fx:Declarations>

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

</fx:Declarations>

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

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

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

 fontFamily="verdana">

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

 fontFamily="verdana"/>

</mx:FormItem>

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

 fontFamily="verdana">

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

</mx:FormItem>

<mx:FormItem>

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

</mx:FormItem>

</mx:Form>

</s:Panel>

</s:Application>

Output:

Running Application:

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

Download this code

Related Tags for SwitchSymbolFormatter in FLex4:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.