Share on Google+Share on Google+

SwitchSymbolFormatter in FLex4

Advertisement
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

Advertisements

Advertisement

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.