| 包 | mx.formatters |
| 类 | public class SwitchSymbolFormatter |
| 继承 | SwitchSymbolFormatter Object |
| 语言版本: | ActionScript 3.0 |
| 产品版本: | Flex 3 |
| 运行时版本: | Flash Player 9, AIR 1.1 |
例如,您可以为 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 对象的脚本实现。
相关 API 元素
公共方法
| 方法 | 由以下参数定义 | ||
|---|---|---|---|
SwitchSymbolFormatter(numberSymbol:String = "#")
构造函数。 | SwitchSymbolFormatter | ||
通过使用格式模式设置源 String 的格式可创建新的 String。 | SwitchSymbolFormatter | ||
![]() |
表示对象是否已经定义了指定的属性。 | Object | |
![]() |
表示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
表示指定的属性是否存在、是否可枚举。 | Object | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
构造函数详细信息
SwitchSymbolFormatter | () | 构造函数 |
方法详细信息
formatValue | () | 方法 |
示例 如何使用本示例
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>
Tue Jun 12 2018, 11:04 AM Z
隐藏继承的公共属性
显示继承的公共属性