首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

Flex4讯息提示框Alert

2012-10-20 
Flex4消息提示框Alert在任何BS项目中,消息提示框都是非常常见的功能组件,flex在AIR的渲染下,消息提示框也

Flex4消息提示框Alert

在任何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         2Alert.YES        1Alert.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对象也会跟着改变。

?

?

最后看下运行效果:

?
Flex4讯息提示框Alert


Flex4讯息提示框Alert


Flex4讯息提示框Alert
?
?
?

1 楼 remoteJavaSky 2011-07-02   其实Alert就是个对Panel的包装吧,显然是单态的 2 楼 gs80140 2011-10-12   Flex4 Spark 组件没有Alert
那我做一个单纯的只用Spark的项目,如何使用Alert?

热点排行