Referência do ActionScript® 3.0 para Adobe® Flash® Platform
Início  |  Ocultar listas de Pacotes e Classes |  Pacotes  |  Classes  |  Novidades  |  Índice  |  Apêndices  |  Por que inglês?
Filtros: AIR 30.0 e anterior, Flash Player 30.0 e anterior, Flash Lite 4
Flex 4.6 e anterior, Flash Pro CS6 e anterior
Ocultar filtros
mx.formatters 

ZipCodeFormatter  - AS3 Flex

Pacotemx.formatters
Classepublic class ZipCodeFormatter
HerançaZipCodeFormatter Inheritance Formatter Inheritance Object

Versão da linguagem: ActionScript 3.0
Versão de produto: Flex 3
Versões de runtime: Flash Player 9, AIR 1.1

The ZipCodeFormatter class formats a valid number into one of the following formats, based on a user-supplied formatString property.
  • #####-####
  • ##### ####
  • #####
  • ### ### (Canadian)

A six-digit number must be supplied for a six-digit mask. If you use a five-digit or a nine-digit mask, you can use either a five-digit or a nine-digit number for formatting.

If an error occurs, an empty String is returned and a String that describes the error is saved to the error property. The error property can have one of the following values:

  • "Invalid value" means an invalid numeric value is passed to the format() method. The value should be a valid number in the form of a Number or a String, except for Canadian postal code, which allows alphanumeric values, or the number of digits does not match the allowed digits from the formatString property.
  • "Invalid format" means any of the characters in the formatString property do not match the allowed characters specified in the validFormatChars property, or the number of numeric placeholders does not equal 9, 5, or 6.

Sintaxe MXMLexpandedOcultar sintaxe MXML

The <mx:ZipCodeFormatter> tag inherits all of the tag attributes of its superclass, and adds the following tag attributes:

  <mx:ZipCodeFormatter
    formatString="#####|#####-####|### ###"
  />
  

Veja os exemplos

Elementos da API relacionados



Propriedades públicas
 PropriedadeDefinido por
 Inheritedconstructor : Object
Uma referência ao objeto de classe ou à função de construtor de uma determinada ocorrência de objeto.
Object
 Inheritederror : String
Description saved by the formatter when an error occurs.
Formatter
  formatString : String
The mask pattern.
ZipCodeFormatter
Propriedades protegidas
 PropriedadeDefinido por
 InheritedresourceManager : IResourceManager
[somente leitura] A reference to the object which manages all of the application's localized resources.
Formatter
Métodos públicos
 MétodoDefinido por
  
Constructor.
ZipCodeFormatter
  
[substituir] Formats the String by using the specified format.
ZipCodeFormatter
 Inherited
Indica se um objeto tem uma propriedade especificada definida.
Object
 Inherited
Indica se uma ocorrência da classe Object está na cadeia de protótipos do objeto especificado como o parâmetro.
Object
 Inherited
Indica se a propriedade especificada existe e é enumerável.
Object
 Inherited
Define a disponibilidade de uma propriedade dinâmica para operações de repetição.
Object
 Inherited
Retorna a representação da string deste objeto, formatado segundo as convenções específicas para a localidade.
Object
 Inherited
Retorna a representação de string do objeto especificado.
Object
 Inherited
Retorna o valor primitivo do objeto especificado.
Object
Métodos protegidos
 MétodoDefinido por
 Inherited
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
Detalhes da propriedade

formatString

propriedade
formatString:String

Versão da linguagem: ActionScript 3.0
Versão de produto: Flex 3
Versões de runtime: Flash Player 9, AIR 1.1

The mask pattern. Possible values are "#####-####", "##### ####", "#####", "###-###" and "### ###".

O valor padrão é "#####".



Implementação
    public function get formatString():String
    public function set formatString(value:String):void
Detalhes do construtor

ZipCodeFormatter

()Construtor
public function ZipCodeFormatter()

Versão da linguagem: ActionScript 3.0
Versão de produto: Flex 3
Versões de runtime: Flash Player 9, AIR 1.1

Constructor.

Detalhes do método

format

()método
override public function format(value:Object):String

Versão da linguagem: ActionScript 3.0
Versão de produto: Flex 3
Versões de runtime: Flash Player 9, AIR 1.1

Formats the String by using the specified format. If the value cannot be formatted, return an empty String and write a description of the error to the error property.

Parâmetros

value:Object — Value to format.

Retorna
String — Formatted String. Empty if an error occurs. A description of the error condition is written to the error property.
ZipCodeFormatterExample.mxml
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate ZipCodeFormatter. -->
<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.events.ValidationResultEvent;

            private var vResult:ValidationResultEvent;

            // Event handler to validate and format input.
            private function Format():void {
                vResult = zcVal.validate();

                if (vResult.type == ValidationResultEvent.VALID) {
                    formattedZipcode.text = zipFormatter.format(zip.text);
                } else {
                    formattedZipcode.text = "";
                }
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <mx:ZipCodeFormatter id="zipFormatter" formatString="#####-####"/>
        <mx:ZipCodeValidator id="zcVal" source="{zip}" property="text" allowedFormatChars=""/>
    </fx:Declarations>

    <s:Panel title="ZipCodeFormatter Example"
            width="75%" height="75%" 
            horizontalCenter="0" verticalCenter="0">
        <mx:Form left="10" right="10" top="10" bottom="10">
            <mx:FormItem label="Enter a 5 or 9 digit U.S. ZIP code:" width="100%">
                <s:TextInput id="zip" text=""/>
            </mx:FormItem>
            <mx:FormItem label="Formatted ZIP code: " width="100%">
                <s:TextInput id="formattedZipcode" text="" editable="false"/>
            </mx:FormItem>
            <mx:FormItem>
                <s:Button label="Validate and Format" click="Format();"/>
            </mx:FormItem>
        </mx:Form>
    </s:Panel>

</s:Application>




[ X ]Por que inglês?
O conteúdo na Referência do ActionScript 3.0 aparece em inglês

Nem todas as partes da Referência do ActionScript 3.0 estão traduzidas em todos os idiomas. Quando um elemento de um idioma não está traduzido, ele é exibido em inglês. Por exemplo, a classe ga.controls.HelpBox não está traduzida em nenhum idioma. Por isso, na versão da referência em português do Brasil, a classe ga.controls.HelpBox é exibida em inglês.