| 包 | mx.formatters |
| 类 | public class Formatter |
| 继承 | Formatter Object |
| 子类 | CurrencyFormatter, DateFormatter, NumberFormatter, PhoneFormatter, ZipCodeFormatter |
format() 方法。
MXML 语法
隐藏 MXML 语法The Formatter class defines the following tag attributes, which all of its subclasses inherit:
<mx:tagname
Properties
error=""
/>
另请参见
| 属性 | 定义方 | ||
|---|---|---|---|
![]() | constructor : Object
对类对象或给定对象实例的构造函数的引用。 | Object | |
| defaultInvalidFormatError : String [静态] 为 formatter 指定的格式字符串无效时出现的错误消息。 | Formatter | ||
| defaultInvalidValueError : String [静态] 为 formatter 指定的值无效时出现的错误消息。 | Formatter | ||
| error : String 发生错误时由 formatter 保存的说明。 | Formatter | ||
![]() | prototype : Object [静态]
对类或函数对象的原型对象的引用。 | Object | |
| 属性 | 定义方 | ||
|---|---|---|---|
| resourceManager : IResourceManager [只读 (read-only)] 引用管理所有应用程序本地化资源的对象。 | Formatter | ||
| 方法 | 定义方 | ||
|---|---|---|---|
构造函数。 | Formatter | ||
设置值的格式,并返回一个包含已格式化的新值的 String。 | Formatter | ||
![]() |
指示对象是否已经定义了指定的属性。 | Object | |
![]() |
指示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
指示指定的属性是否存在、是否可枚举。 | Object | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
| 方法 | 定义方 | ||
|---|---|---|---|
构建 Formatter 时将调用此方法,并且每当 ResourceManager 调度“change”事件来指示本地化资源已经过某种更改时,都会再次调用此方法。 | Formatter | ||
| defaultInvalidFormatError | 属性 |
defaultInvalidFormatError:String [读写] 为 formatter 指定的格式字符串无效时出现的错误消息。
默认值为 "Invalid format".
public static function get defaultInvalidFormatError():String public function set defaultInvalidFormatError(value:String):void| defaultInvalidValueError | 属性 |
defaultInvalidValueError:String [读写] 为 formatter 指定的值无效时出现的错误消息。
默认值为 "Invalid value".
public static function get defaultInvalidValueError():String public function set defaultInvalidValueError(value:String):void| error | 属性 |
public var error:String发生错误时由 formatter 保存的说明。有关此属性的可能值,请参阅每个 formatter 的说明。
子类必须在 format() 方法中设置此值。
| resourceManager | 属性 |
resourceManager:IResourceManager [只读 (read-only)] 引用管理所有应用程序本地化资源的对象。此项是 singleton 实例,实现 IResourceManager 接口。
此属性可用作数据绑定的源。修改此属性后,将调度 unused 事件。
protected function get resourceManager():IResourceManager| Formatter | () | 构造函数 |
public function Formatter()构造函数。
| format | () | 方法 |
public function format(value:Object):String设置值的格式,并返回一个包含已格式化的新值的 String。所有子类都必须覆盖此方法,以实现 formatter。
参数
value:Object — 要格式化的值。 |
String — 格式化的字符串。 |
| resourcesChanged | () | 方法 |
protected function resourcesChanged():void
构建 Formatter 时将调用此方法,并且每当 ResourceManager 调度 "change" 事件来指示本地化资源已经过某种更改时,都会再次调用此方法。
在下列情形中调度此事件:设置 ResourceManager 的 localeChain 属性时,资源模块完成加载时,以及调用 ResourceManager 的 update() 方法时。
子类应覆盖此方法,并在调用 super.resourcesChanged() 后,执行任何适当的操作以响应新资源值。
<?xml version="1.0"?>
<!-- Simple example to demonstrate the Formatter class. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
// Event handler to format the input.
private function Format():void
{
// The format() method returns the formatted String,
// or an empty String if there is an error.
var formattedVal:String = numberFormatter.format(inputVal.text);
if (formattedVal.length==0) {
// If there is an error, the Format.error property
// contains the reason.
formattedNumber.text=numberFormatter.error;
}
else {
formattedNumber.text=formattedVal;
}
}
]]>
</mx:Script>
<mx:NumberFormatter id="numberFormatter"/>
<mx:Panel title="NumberFormatter Example" width="75%" height="75%"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
<mx:Form>
<mx:FormItem label="Enter number - a letter is invalid:">
<mx:TextInput id="inputVal" text="" width="75%"/>
</mx:FormItem>
<mx:FormItem label="Formatted number: ">
<mx:TextInput id="formattedNumber" editable="false" width="75%"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Validate and Format" click="Format();"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:Application>