在任何BS項目中,消息提示框都是非常常見的功能組件,flex在AIR的渲染下,消息提示框也是做得非常漂亮美觀。
?
Flex的消息提示框由mx.controls.Alert類負(fù)責(zé)創(chuàng)建,通常通過調(diào)用靜態(tài)方法show(即可實現(xiàn)提示框的創(chuàng)建):
public static show ( text:String, //消息提示內(nèi)容 title:String=null, //標(biāo)題 flags:uint=mx.controls.Alert.OK, //按鈕組合 parent:Sprite=null, //Alert 控件的父對象 clickListener:Function=null, //指定 click 事件的偵聽器 iconClass:Class=null, //指定對話框中消息文本左側(cè)的圖標(biāo) defaultButton:uint=mx.controls.Alert.OK //使用一個標(biāo)志參數(shù)的合法值指定默認(rèn)按鈕。當(dāng)用戶按下回車時,此按鈕就被選中,其默認(rèn)值是 Alert.OK. )
?
show方法內(nèi)所有參數(shù)都是非必選的。
參數(shù)flags表示彈出框下面生成幾種按鈕,alert類提供了四個按鈕:是、否、確定和取消,由四個整數(shù)抽象表示:
Alert.OK 4 Alert.NO 2 Alert.YES 1 Alert.CANCEL 8
?具體使用方法詳見后面的代碼。
參數(shù)clickListener可實現(xiàn)點擊按鈕事件監(jiān)聽,也就是說可以通過監(jiān)聽來判斷用戶點擊的是哪個按鈕,從而根據(jù)不同選擇實現(xiàn)不同操作。
?
?
下面來看一個實例:在界面上有三個按鈕,每點擊一個按鈕彈出一個提示框。這個功能非常簡單,只需要給每個button綁定click事件即可:
<fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.CloseEvent; protected function button1_clickHandler(event:MouseEvent):void { var myAlert:Alert = Alert.show("顯示對話框...","提示"); myAlert.height = 200; //高度 myAlert.width = 200; //寬度 } protected function button2_clickHandler(event:MouseEvent):void { Alert.show("你確定此操作嗎?","提示",Alert.OK|Alert.CANCEL|Alert.YES|Alert.NO,this,handler); } protected function button3_clickHandler(event:MouseEvent):void { Alert.yesLabel = "喲系yes"; Alert.noLabel = "呀滅no"; Alert.cancelLabel = "哦cancel"; var myAlert:Alert = Alert.show("選擇操作...","提示",1|2,this,handler); } private function handler(e:CloseEvent):void{ //顯示事件選擇的值 Alert.show(e.detail.toString()); } ]]> </fx:Script> <fx:Declarations> <!-- 將非可視元素(例如服務(wù)、值對象)放在此處 --> </fx:Declarations> <s:Button label="按鈕1" click="button1_clickHandler(event)"/> <s:Button label="按鈕2" click="button2_clickHandler(event)"/> <s:Button label="按鈕3" click="button3_clickHandler(event)"/>
?需要注意的是Alert.yesLabel、Alert.noLabel、Alert.cancelLabel等等set方法是全局的,如果相應(yīng)屬性值改變,則其它Alert對象也會跟著改變。
?
?
最后看下運行效果:
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
