Alert是我们常用的一个类,很简单,但是我想越基础的东西,如果有了很好的理解之后,也会对自己有所提高。
Alert中最重要的方法就是show()了,因为其中的参数就可以定义弹出窗体的所有属性了,所以要对其充分认识,对于Alert总结了以下几点:
1、在mx.controls包中;
2、show()中的参数:
show(text:String = "", title:String = "", flags:uint = 0x4, parent:Sprite = null, closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4):
1) text:就是弹出窗口的提示信息;如:“确定删除你选择的照片吗?”等等
2)title:就是弹出窗口的title,显示在左上角;如:“警告”;
3)flags:这个参数是最重要的一个了,因为它决定了显示哪些按钮和模态的设定,可以看到它的类型是unit,所以是一个个的数字;Alert类中就有这样的常量,YES(0x0001),NO(0x0002),NONMODAL(0x8000),OK(0x0004),CANCEL(0x0008)等;如果要多个按钮,用“|”隔开;
如:
Alert.show("Do you want to save your changes?", "Save Changes", Alert.NONMODAL|Alert.OK|Alert.NO, this,alertClickHandler,icon1);
由于flags是unit类型,直接写常数也是可以的,如:
Alert.show("Select a color:","Color Selection",1|2|8,this,null,icon1);
4)parent:弹出的Alert窗体,在其上居中;
5)closeHandler:关闭Alert窗体事件相应的函数;通过CloseEvent的detail属性可以获得用户选择的按钮;
如:
private function alertClickHandler(event:CloseEvent):void {
if (event.detail==Alert.YES)status.text="You answered Yes";else
status.text="You answered No";}
6)iconClass:用于设定弹出窗体的图标,利用Embed标签导入外部资源,然后可以用于这里;
7)defaultButtonFlag:用于设定默认按钮;
其他属性查帮助即可。
Alert.show()里面有多个属性,其中排在第三是flags,这个属性作用是在弹出的Alert提示框里面显示那一个或多个按钮,文档和书籍一般 只写该属性可以自由组合 Alert.OK, Alert.CANCEL,Alert.YES ,Alert.NO四个选项,并用“|”分隔,其实也可以用数字编号代替的,用数字编号更为简便,以下是编号对应的按钮组合表,一共有16个数字编号(其 实只有15种组合)。
1- Alert.YES
2- Alert.NO
3- Alert.YES | Alert.NO
4- Alert.OK
5- Alert.OK | Alert.YES
6- Alert.OK | Alert.NO
7- Alert.OK | Alert.YES | Alert.NO
8- Alert.CANCEL
9- Alert.YES | Alert.CANCEL
10- Alert.NO | Alert.CANCEL
11- Alert.YES | Alert.NO | Alert.CANCEL
12- Alert.OK | Alert.CANCEL
13- Alert.OK | Alert.YES | Alert.CANCEL
14- Alert.OK | Alert.NO | Alert.CANCEL
15- Alert.OK | Alert.YES | Alert.NO | Alert.CANCEL
16- Alert.OK (和4一样)
17开始返回到1重新按顺序循环………..而flags属性不填写的话一般默认值为Alert.OK,也就是4或16。
例子
<?xml version="1.0"?>
<!-- Simple example to demonstrate the Alert control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
// Event handler function uses a static method to show
// a pop-up window with the title, message, and requested buttons.
private function clickHandler(event:Event):void {
Alert.show("Do you want to save your changes?", "Save Changes", 3, this, alertClickHandler);
}
// Event handler function for displaying the selected Alert button.
private function alertClickHandler(event:CloseEvent):void {
if (event.detail==Alert.YES)
status.text="You answered Yes";
else
status.text="You answered No";
}
// Event handler function changes the default Button labels and sets the
// Button widths. If you later use an Alert with the default Buttons,
// you must reset these values.
private function secondClickHandler(event:Event):void {
Alert.buttonWidth = 100;
Alert.yesLabel = "Magenta";
Alert.noLabel = "Blue";
Alert.cancelLabel = "Green";
Alert.show("Select a color:","Color Selection",1|2|8,this);
// Set the labels back to normal:
Alert.yesLabel = "Yes";
Alert.noLabel = "No";
}
]]>
</mx:Script>
<mx:Panel title="Alert Control Example" width="75%" horizontalAlign="center" paddingTop="10">
<mx:Text width="100%" color="blue" textAlign="center" fontSize="12"
text="点击下面按钮弹出一个简单的Alert窗口."/>
<mx:Button label="点击我" click="Alert.show('Hello World!', 'Message');"/>
<mx:Text width="100%" color="blue" textAlign="center" fontSize="12"
text="点击下面按钮弹出一个Alert窗口,并且捕获你按下的按钮."/>
<mx:Button label="点击我" click="clickHandler(event);"/>
<mx:Label id="status" fontWeight="bold"/>
<mx:Text width="100%" color="blue" textAlign="center" fontSize="12"
text="点击下面按钮弹出一个包括自定义标签按钮的Alert窗口."/>
<mx:Button label="点击我" click="secondClickHandler(event);"/>
</mx:Panel>
</mx:Application>
分享到:
相关推荐
flex中Alert是很常用的,该源码主要是对Alert的样式设置。
Flex 自定义Alert 4版本自定义Alert 4版本自定义Alert 4版本自定义Alert 4版本
flex接收网页参数,flex与js交互,flex调用js,js调用flex
Flex中如何检测Alert控件是否closed的例子.zip
flex中文帮助flex中文帮助flex中文帮助flex中文帮助
本次资源就是针对一次编译原理实验,实验的内容就是用flex工具自动构造词法分析程序
flex builder 编译器参数 就是点工程属性里的option里填的
一步一步的利用flex做tiny语言的词法分析的过程,包含截图和代码,有注释
flex获得html容器传递的url参数值
flex实现对图片的旋转与拖动,简单的小例子,希望对大家有所帮助
Adobe Flex Builder 3 中组件之间的参数传递(主要是给大家学习)
原创。包含使用说明、.l文件、测试文档以及所有的生成文档
flex中文帮助文档flex中文帮助文档
只要你有flex运行环境就行 把这个文件拷贝进去 然后在你访问的地址栏中记得加个参数 如http://111:80/tt/a.html?name=csdn 就这样
Flex编程实现词法分析目的: 了解C--语法 掌握Flex创建词法分析的基本步骤 掌握编写Flex源文件 学会正则表达式的书写 了解Flex生成的词法分析函数yylex(),并且思考yylex()与语法分析之间的联系 txt中为实验代码,请...
Flex做的非常好的一个效果例子,Flex开门,关门,翻转,效果。
新建MXML应用, 将文档中的代码全部复制到新建的MXML中( 替换所有内容)。 文档中的注释说明了具体使用方法。
flex中moduleLoader动态加载module时传递参数源代码
flex 自动关闭的alert 默认关闭时间1.5秒
flex-2.5.2,编译原理语法分析中用到