| Package | mx.formatters |
| Class | public class Formatter |
| Inheritance | Formatter Object |
| Subclasses | CurrencyFormatter, DateFormatter, NumberFormatter, PhoneFormatter, ZipCodeFormatter |
format() method.
MXML Syntax
Hide MXML Syntax
The Formatter class defines the following tag attributes, which all of its subclasses inherit:
<mx:tagname
Properties
error=""
/>
See also
| Property | Defined by | ||
|---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
| error : String
Description saved by the formatter when an error occurs.
| Formatter | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| Property | Defined by | ||
|---|---|---|---|
| defaultInvalidFormatError : String = "Invalid format"
Error message for an invalid format string specified to the formatter.
| Formatter | ||
| defaultInvalidValueError : String = "Invalid value"
Error message for an invalid value specified to the formatter.
| Formatter | ||
| packageResources : ResourceBundle
[static]
A ResourceBundle object containing all symbols
from
formatters.properties. | Formatter | ||
| Method | Defined by | ||
|---|---|---|---|
|
Constructor.
| Formatter | ||
|
Formats a value and returns a String
containing the new, formatted, value.
| Formatter | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
![]() |
Returns the string representation of the specified object.
| Object | |
![]() |
Returns the primitive value of the specified object.
| Object | |
| defaultInvalidFormatError | property |
protected var defaultInvalidFormatError:String = "Invalid format"Error message for an invalid format string specified to the formatter.
The default value is "Invalid format".
| defaultInvalidValueError | property |
protected var defaultInvalidValueError:String = "Invalid value"Error message for an invalid value specified to the formatter.
The default value is "Invalid value".
| error | property |
public var error:StringDescription 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.
| packageResources | property |
protected static var packageResources:ResourceBundle
A ResourceBundle object containing all symbols
from formatters.properties.
| Formatter | () | constructor |
public function Formatter()Constructor.
| format | () | method |
public function format(value:Object):StringFormats a value and returns a String containing the new, formatted, value. All subclasses must override this method to implement the formatter.
Parametersvalue:Object — Value to be formatted.
|
String —
The formatted string.
|
<?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>
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/201/langref/mx/formatters/Formatter.html