在任何BS項目中,消息提示框都是非常常見的功能組件,flex在AIR的渲染下,消息提示框也是做得非常漂亮美觀。
?
Flex的消息提示框由mx.controls.Alert類負責創建,通常通過調用靜態方法show(即可實現提示框的創建):
public static show ( text:String, //消息提示內容 title:String=null, //標題 flags:uint=mx.controls.Alert.OK, //按鈕組合 parent:Sprite=null, //Alert 控件的父對象 clickListener:Function=null, //指定 click 事件的偵聽器 iconClass:Class=null, //指定對話框中消息文本左側的圖標 defaultButton:uint=mx.controls.Alert.OK //使用一個標志參數的合法值指定默認按鈕。當用戶按下回車時,此按鈕就被選中,其默認值是 Alert.OK. )
?
show方法內所有參數都是非必選的。
參數flags表示彈出框下面生成幾種按鈕,alert類提供了四個按鈕:是、否、確定和取消,由四個整數抽象表示:
Alert.OK 4 Alert.NO 2 Alert.YES 1 Alert.CANCEL 8
?具體使用方法詳見后面的代碼。
參數clickListener可實現點擊按鈕事件監聽,也就是說可以通過監聽來判斷用戶點擊的是哪個按鈕,從而根據不同選擇實現不同操作。
?
?
下面來看一個實例:在界面上有三個按鈕,每點擊一個按鈕彈出一個提示框。這個功能非常簡單,只需要給每個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> <!-- 將非可視元素(例如服務、值對象)放在此處 --> </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方法是全局的,如果相應屬性值改變,則其它Alert對象也會跟著改變。
?
?
最后看下運行效果:
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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