mx.formatters
SwitchSymbolFormatter クラス
SwitchSymbolFormatter クラス
SwitchSymbolFormatter クラスは、主に独自のカスタムフォーマッタを作成するために使用するユーティリティクラスです。SwitchSymbolFormatter クラスの formatString プロパティは、フォーマットされたストリングをフォーマットパターンの定義として受け取ります。このフォーマットパターンには、英数字とプレースホルダー文字を組み合わせて使用できます。パターンで使用する文字には、ストリングの数値の部分の値に対して一定であれば、任意の文字を指定できます。ただし、フォーマットする値は数値である必要があります。ソース値で指定する桁数は、パターンストリングで定義されている桁数と一致する必要があります。これは、SwitchSymbolFormatter オブジェクトを呼び出すスクリプトで処理する必要があります。
例を参照するにはここをクリックしてください
関連項目
PhoneFormatter
| formatValue( format, source)
: String
フォーマットパターンを使用してソースストリングをフォーマットすることによって、新しいストリングを作成します。 |
SwitchSymbolFormatter
SwitchSymbolFormatter( nSymbol)
コンストラクタ。SwitchSymbolFormatter オブジェクトを作成します。
パラメータ
nSymbol - パターン文字として使用する文字を表します。
formatValue
formatValue( format, source)
: String
フォーマットパターンを使用してソースストリングをフォーマットすることによって、新しいストリングを作成します。
パラメータ
format - ユーザーが要求したパターン追加を定義するストリングを表します。
source - 有効な数値並びを表します。必要に応じてアルファ文字を使用できます。
戻り値
フォーマットしたストリング。
| SwitchSymbolFormatterExample.mxml |
<?xml version="1.0" encoding="utf-8"?>
<!-- SwitchSymbol formatter の使用方法を示す簡単な例 -->
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" backgroundColor="#FFFFFF">
<mx:Script>
<![CDATA[
function Format()
{
if(mx.validators.Validator.isValid(this,'CheckModel.Zip'))
{
var switcher;
switcher = new mx.formatters.SwitchSymbolFormatter('#');
formattedzipcode.text = switcher.formatValue("Formatted Zip code: ##-#-## !!!!",
CheckModel.Zip);
}
else
formattedzipcode.text= "";
}
]]>
</mx:Script>
<mx:Panel title="Validate and Format Panel" backgroundColor="#0C8BF3">
<mx:Model id="CheckModel">
<Zip>{zip.text}</Zip>
</mx:Model>
<mx:Label text="Enter below 5 digit Zip code to be validated and formatted:"color="#FFFFFF"/>
<mx:TextInput id="zip" text="Enter zip code here" maxChars="5"/>
<mx:Button label="Validate and Format" click="Format();" width="160"/>
<mx:TextInput id="formattedzipcode" editable="false" color="#0000FF"/>
</mx:Panel>
<!-- ZipCodeValidator がユーザー入力を検証します。 -->
<mx:ZipCodeValidator field="CheckModel.Zip" wrongLengthError="Invalid Format, please enter 5 digit zip code."
allowedFormatChars="#" domain="US Only"/>
</mx:Application>
|