套件 | mx.formatters |
類別 | public class Formatter |
繼承 | Formatter Object |
實作 | IFormatter |
子類別 | CurrencyFormatter, DateFormatter, NumberFormatter, PhoneFormatter, ZipCodeFormatter |
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
format()
method.
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 [靜態]
Error message for an invalid format string specified to the formatter. | Formatter | ||
defaultInvalidValueError : String [靜態]
Error messages for an invalid value specified to the formatter. | Formatter | ||
error : String
Description saved by the formatter when an error occurs. | Formatter |
屬性 | 定義自 | ||
---|---|---|---|
resourceManager : IResourceManager [唯讀]
A reference to the object which manages
all of the application's localized resources. | Formatter |
方法 | 定義自 | ||
---|---|---|---|
Constructor. | Formatter | ||
Formats a value and returns a String
containing the new, formatted, value. | Formatter | ||
指出物件是否有已定義的指定屬性。 | Object | ||
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。 | Object | ||
指出指定的屬性是否存在,以及是否可列舉。 | Object | ||
為迴圈作業設定動態屬性的可用性。 | Object | ||
傳回代表此物件的字串,根據地區特定慣例進行格式化。 | Object | ||
會傳回指定之物件的字串形式。 | Object | ||
會傳回指定之物件的基本值。 | Object |
方法 | 定義自 | ||
---|---|---|---|
This method is called when a Formatter is constructed,
and again whenever the ResourceManager dispatches
a "change" Event to indicate
that the localized resources have changed in some way. | Formatter |
defaultInvalidFormatError | 屬性 |
defaultInvalidFormatError:String
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
Error message for an invalid format string specified to the formatter.
預設值為 "Invalid format"。
實作
public static function get defaultInvalidFormatError():String
public static function set defaultInvalidFormatError(value:String):void
defaultInvalidValueError | 屬性 |
defaultInvalidValueError:String
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
Error messages for an invalid value specified to the formatter.
預設值為 "Invalid value"。
實作
public static function get defaultInvalidValueError():String
public static function set defaultInvalidValueError(value:String):void
error | 屬性 |
public var error:String
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
Description saved by the formatter when an error occurs. For the possible values of this property, see the description of each formatter.
Subclasses must set this value
in the format()
method.
resourceManager | 屬性 |
resourceManager:IResourceManager
[唯讀] 語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
A reference to the object which manages all of the application's localized resources. This is a singleton instance which implements the IResourceManager interface.
此屬性可以做為資料繫結的來源。一旦修改此屬性,將傳送 unused
事件。
實作
protected function get resourceManager():IResourceManager
Formatter | () | 建構函式 |
public function Formatter()
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
Constructor.
format | () | 方法 |
public function format(value:Object):String
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
Formats a value and returns a String containing the new, formatted, value. All subclasses must override this method to implement the formatter.
參數
value:Object — Value to be formatted.
|
String — The formatted string.
|
resourcesChanged | () | 方法 |
protected function resourcesChanged():void
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
This method is called when a Formatter is constructed,
and again whenever the ResourceManager dispatches
a "change"
Event to indicate
that the localized resources have changed in some way.
This event will be dispatched when you set the ResourceManager's
localeChain
property, when a resource module
has finished loading, and when you call the ResourceManager's
update()
method.
Subclasses should override this method and, after calling
super.resourcesChanged()
, do whatever is appropriate
in response to having new resource values.
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the Formatter class. --> <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[ // 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; } } ]]> </fx:Script> <fx:Declarations> <mx:NumberFormatter id="numberFormatter" /> </fx:Declarations> <s:Panel title="NumberFormatter Example" width="75%" height="75%" horizontalCenter="0" verticalCenter="0"> <mx:Form left="10" right="10" top="10" bottom="10"> <mx:FormItem label="Enter number - a letter is invalid:"> <s:TextInput id="inputVal" text="" width="75%"/> </mx:FormItem> <mx:FormItem label="Formatted number: "> <s:TextInput id="formattedNumber" editable="false" width="75%"/> </mx:FormItem> <mx:FormItem> <s:Button label="Validate and Format" click="Format();"/> </mx:FormItem> </mx:Form> </s:Panel> </s:Application>
Tue Jun 12 2018, 03:47 PM Z