Flex中Alert参数分析
来源:互联网 发布:金融lse本科知乎 编辑:程序博客网 时间:2024/05/22 09:38
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参数分析
- Flex中Alert参数分析
- Flex中Alert控件使用
- Flex- Alert.show()的Flags参数
- Flex Alert
- flex Alert
- Flex中DateField,Alert的中文汉化
- Flex如何在Alert中显示超链接
- Flex中DateField,Alert的中文汉化
- Flex alert中按钮改中文
- Response.Write(" alert( 中加参数
- Flex中自定义Alert控件按钮(Button)样式的例子
- Flex中自定义Alert控件按钮(Button)样式的例子
- [Flex]在Flex中传递参数
- Flex Alert组件
- flex alert 警告框
- Flex Alert组件
- Flex-Alert学习篇
- eclipse多行注释方法
- 2010-9-17~2010-9-19
- 图形化强密码设置法
- 一个大学男生写的、没有颓废、没有抱怨、没有消极、写的很深刻,...
- PHP添加图片水印功能
- Flex中Alert参数分析
- 勤奋是一生的资源
- 多文档接口(MDI)
- S3C2440 LCD控制器描述
- [2010-09-20].NET 2.0 C#下利用ChineseLunisolarCalendar类农历的实现
- 问题,提示,记录
- 《Win32Asm与RadAsm开发教程》第三部视频(对话框程序实例),2011-1-28(本系列更新完毕)!
- Scrum
- Java Mondrian3.2 的错误,围困了好久了