Flex中Alert控件使用!

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.CloseEvent;
		
            //点击按钮调用事件       
            private function clickHandler(event:Event):void {
            	//参数:显示文本,标题,显示操作按钮,
            	Alert.yesLabel = "YES";
                Alert.noLabel = "NO";
                Alert.show("请问您想保存所做的改变么?", "保存", (Alert.YES | Alert.NO) , this, alertClickFirst);
            }
        
            // 关闭后触发的事件
            private function alertClickFirst(event:CloseEvent):void {
                if (event.detail==Alert.YES)
                    status.text="您选择了YES!";
                else
                    status.text="您选择了NO!";
            }
			
			//设置按钮显示文字
            private function secondClickHandler(event:Event):void {
                Alert.buttonWidth = 100;
                Alert.yesLabel = "粉色";
                Alert.noLabel = "蓝色";
                Alert.cancelLabel = "绿色";
                Alert.show("Select a color:","Color Selection",1|2|8,this,alertClickSecond);
            }
            // 关闭后触发的事件
            private function alertClickSecond(event:CloseEvent):void{
            	if(event.detail == Alert.YES){
            		color.text= "粉色";
            	}else if(event.detail == Alert.NO){
            		color.text= "蓝色";
            	}else if(event.detail == Alert.CANCEL){
            		color.text= "绿色";
            	}
            }
        ]]>
    </mx:Script>

    <mx:Panel title="Alert Control Example" width="75%" horizontalAlign="center" paddingTop="10" x="115" y="82">
      
      <mx:Text width="100%" color="blue" textAlign="center" fontSize="20"
          text="普通Alert例子,显示标题和Hello Word!"/>
      <mx:Button label="点我" click="Alert.show('Hello World!', 'Message');" fontSize="20"/>

      <mx:Text width="100%" color="blue" textAlign="center" fontSize="20"
          text="出现选择框的Alert例子!"/>
      <mx:Button label="点我" click="clickHandler(event);" fontSize="20"/>
      <mx:Label id="status" fontWeight="bold" fontSize="20"/>

      <mx:Text width="100%" color="blue" textAlign="center" fontSize="20"
          text="使用自定义按钮的Alert例子"/>
      <mx:Button label="点我" click="secondClickHandler(event); " fontSize="20"/>
      <mx:Label id="color" fontWeight="bold" fontSize="20"/>
    </mx:Panel>
    	
</mx:Application>

 

以上是关于Flex中的Alert控件的几种简单的使用方式

 

Alert.show()方法
public static function show(text:String = "", title:String = "", flags:uint = 0x4, parent:Sprite = null, closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4):Alert

 

 

弹出 Alert 控件的静态方法。在 Alert 控件中选择一个按钮或按下 Esc 键时,将关闭该控件。

参数

  text:String (default = "") — 在 Alert 控件中显示的文本字符串。此文本将在警告对话框中居中显示。
 
  title:String (default = "") — 标题栏中显示的文本字符串。此文本左对齐。
 
  flags:uint (default = 0x4) — Alert 控件中放置的按钮。有效值为 Alert.OKAlert.CANCELAlert.YESAlert.NO。默认值为 Alert.OK。使用按位 OR 运算符可显示多个按钮。例如,传递 (Alert.YES | Alert.NO) 显示“是”和“否”按钮。无论按怎样的顺序指定按钮,它们始终按照以下顺序从左到右显示:“确定”、“是”、“否”、“取消”。
 
  parent:Sprite (default = null) — Alert 控件在其上居中的对象。
 
  closeHandler:Function (default = null) — 按下 Alert 控件上的任意按钮时将调用的事件处理函数。传递给此处理函数的事件对象是 CloseEvent 的一个实例;此对象的 detail 属性包含 Alert.OKAlert.CANCELAlert.YESAlert.NO 值。
 
  iconClass:Class (default = null) — 位于 Alert 控件中文本左侧的图标的类。
 
  defaultButtonFlag:uint (default = 0x4) — 指定默认按钮的位标志。您可以指定一个值,并且只能是 Alert.OKAlert.CANCELAlert.YESAlert.NO 中的一个值。默认值为 Alert.OK。按 Enter 键触发默认按钮,与单击此按钮的效果相同。按 Esc 键触发“取消”或“否”按钮,与选择相应按钮的效果相同。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值