数据格式化
Flex内置格式化组件
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="#FFFFFF" width="500" height="280">
<mx:DateFormatter id="dateFormatShort" formatString="MM/DD/YY"/>
<mx:DateFormatter id="dateFormatMedium" formatString="MMM DD, YY"/>
<mx:DateFormatter id="dateFormatFull" formatString="MMMM DD, YYYY"/>
<mx:Panel title="Simple Formatter"
layout="horizontal" width="100%" height="100%">
<mx:DateChooser id="cal" />
<mx:VBox>
<mx:Label text="{cal.selectedDate}"/>
<mx:Label text="{dateFormatShort.format(cal.selectedDate)}"/>
<mx:Label text="{dateFormatMedium.format(cal.selectedDate)}"/>
<mx:Label text="{dateFormatFull.format(cal.selectedDate)}"/>
</mx:VBox>
</mx:Panel>
</mx:Application>
当格式化组件出现错误信息时
当无错误时,error属性返回空字符串,当出错时返回Invalid Data
<?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>
posted on 2011-03-17 09:44
长春语林科技 阅读(199)
评论(0) 编辑 收藏 所属分类:
flex