---
title: "Flex 之 初学 Alert 控件"
author: "annewman"
date: "2010-06-30T22:29:59Z"
tags: []
categories: ["Web前端"]
slug: "flex-alert"
draft: false
lastmod: "2010-06-30T22:37:31Z"
id: 702986
url: "https://annewman.iteye.com/blog/702986"
---

Alert 控件 常用方法 show

    参数列表

Alert.show(content,title,flags,parent,closeHandle,iconClass,defaultButtonFlag);

   **参数讲解**

   **content:**提示文本

   title:提示标题

   **flags**:出现的按钮

  **parent:**显示的参照对象,一般都用this

  **closeHandle:**回调函数

  **defaultButtonFlag:**默认被选中的按钮，也就是回车时默认执行的按钮

 

**实例演示：**

     实例一：简单提示框

             &lt;mx:Label x="36" y="10" text="简单的提示框" width="80" height="18" fontSize="11"  fontWeight="bold" olor="#FC0202"/&gt;  
  &lt;mx:Button x="51" y="46" label="显示" width="56" id="btn1" click="mx.controls.Alert.show('你好啊','提示')"     fontWeight="bold" color="#000000"/&gt;

    

       实例二:有选择的提示框

    

&lt;mx:Script&gt;  
   
  &lt;![CDATA[  
  import mx.controls.Alert;  
  import mx.events.CloseEvent;    
    
   //弹出附带可选按钮的提示框  
  private function clickHandler(event:Event):void {  
          mx.controls.Alert.show("是否要保存更改？", "保存更改",3, this, alertClickHandler);  
   }   
   //回调方法，以显示被选按钮

   private function alertClickHandler(event:CloseEvent):void {  
         if (event.detail==mx.controls.Alert.YES)  
                status.text = "你选择了 Yes";  
         else  
                status.text = "你选择了 No";  
    }  
  ]]&gt;  
 &lt;/mx:Script&gt;

 

&lt;mx:Label x="36" y="85" text="含有可选按钮的提示框" width="126" color="#F70B06" fontWeight="bold" /&gt;  
  &lt;mx:Button x="51" y="123" label="显示" width="56" id="btn2" color="#000000" click="clickHandler(event)"/&gt;  
  &lt;mx:Label x="10" y="167" id="status" text="结果显示" color="#F70B06" fontWeight="bold"/&gt;

 

实例三：自定义显示按钮

 

              

    private function customButtonClickHandle(event:Event):void{  
    mx.controls.Alert.buttonWidth = 100;  
    mx.controls.Alert.yesLabel = "OK";  
    mx.controls.Alert.noLabel = "No";  
    mx.controls.Alert.cancelLabel = "Cancel";  
    mx.controls.Alert.show("你好啊","提示信息",1|2|8,this,customButtonCloseEvent);  
    //恢复默认  
    mx.controls.Alert.buttonWidth = 60;  
    mx.controls.Alert.yesLabel = "Yes";  
    mx.controls.Alert.noLabel = "No";  
   }  
    private function customButtonCloseEvent(event:CloseEvent):void{  
     if(event.detail == mx.controls.Alert.YES)  
       status2.text = "您选择了OK";  
      else{  
       if(event.detail == mx.controls.Alert.NO)  
        status2.text ="您选择了NO";  
       else  
         status2.text = "您选择了cancel";  
      }  
    }

              

 

&lt;mx:Label x="36" y="193" text="含有自定义按钮的提示框" width="141" color="#F70B06" fontWeight="bold"/&gt;  
  &lt;mx:Button x="51" y="219" label="显示" width="56" id="btn3" color="#000000" click="customButtonClickHandle(event)"/&gt;  
  &lt;mx:Label x="10" y="259" id="status2" text="结果显示" width="106" color="#FA1301" fontWeight="bold"/&gt;

下面附件中带有源码。

   **有个问题请高手回答：**

     **为什么我导入了Alert控件的包。Flex builder还是提示找不到，必须写全才不会有找不到的错误**