| 包 | mx.formatters |
| 类 | public class SwitchSymbolFormatter |
| 继承 | SwitchSymbolFormatter Object |
例如,您可以为 SwitchSymbolFormatter 类指定以下信息:
格式 String:“The SocialSecurity number is: ###-##-####”
输入 String:“123456789”
SwitchSymbolFormatter 类会分析格式 String,并使用输入 String 中的数字按照在输入 String 中指定的顺序替换每个占位符(默认情况下即数字字符 (#))。您可以定义不同的占位符符号,在实例化 SwitchSymbolFormatter 对象时将该符号传递给构造函数即可。
SwitchSymbolFormatter 类将使用这两个字符串创建如下输出 String:
“The SocialSecurity number is: 123-45-6789”
此模式中可以包含任何字符,只要它们在 String 数值部分的所有值中保持一致即可。但是,要格式化的值必须是数字。
源值中提供的位数必须符合模式 String 中定义的位数。这可通过调用 SwitchSymbolFormatter 对象的脚本实现。
另请参见
| 方法 | 定义方 | ||
|---|---|---|---|
SwitchSymbolFormatter(numberSymbol:String = "#") 构造函数。 | SwitchSymbolFormatter | ||
通过使用格式模式设置源 String 的格式可创建新的 String。 | SwitchSymbolFormatter | ||
![]() |
指示对象是否已经定义了指定的属性。 | Object | |
![]() |
指示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
指示指定的属性是否存在、是否可枚举。 | Object | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
| SwitchSymbolFormatter | () | 构造函数 |
public function SwitchSymbolFormatter(numberSymbol:String = "#")构造函数。
参数numberSymbol:String (default = "#") — 要用作模式字符的字符。 |
| formatValue | () | 方法 |
public function formatValue(format:String, source:Object):String通过使用格式模式设置源 String 的格式可创建新的 String。
参数
format:String — 定义包括用户请求的模式的字符串。 | |
source:Object — 有效数字顺序(若有必要,允许使用 Alpha 字符)。 |
String |
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate SwitchSymbolFormatter. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx: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= "";
}
}
]]>
</mx:Script>
<mx:SocialSecurityValidator id="scVal" source="{scNum}" property="text"/>
<mx:Panel title="SwitchSymbolFormatter Example" width="75%" height="75%"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
<mx:Label text="Enter a 9 digit Social Security number with no separator characters:"/>
<mx:TextInput id="scNum" text="" maxChars="9" width="50%"/>
<mx:Button label="Validate and Format" click="Format();"/>
<mx:TextInput id="formattedSCNumber" editable="false" width="75%"/>
</mx:Panel>
</mx:Application>