topical media & game development
professional-flex-code-09-FormatterError.mx
professional-flex-code-09-FormatterError.mx
[swf]
flex
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="#FFFFFF">
<mx:Script>
<![CDATA[
[Bindable]
public var results:String="";
public function formatNow():void {
phoneFormatter.format(phone.text);
// Check value of error property
if(phoneFormatter.error == "Invalid value"){
// append error to results
results+=phoneFormatter.error+" - "+ phone.text + "<br/>";
} else {
// append to results
results+="Valid Phone Number - "+phoneFormatter.format(phone.text) + "<br/>";
// format original TextInput
phone.text=phoneFormatter.format(phone.text);
}
}
]]>
</mx:Script>
<mx:PhoneFormatter id="phoneFormatter"
formatString="( ) - " validPatternChars="#-() "/>
<mx:Panel title="Formatter Error Example" width="300" height="300"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
<mx:HBox>
<mx:Label text="Phone number:" />
<mx:TextInput id="phone" width="75%" change="formatNow()" restrict="0-9()-."/>
</mx:HBox>
<mx:TextArea id="formatterResults" htmlText="{results}" width="100%" height="100%" editable="false"/>
</mx:Panel>
</mx:Application>
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.