Alert提示框备用

来源:互联网 发布:淘宝失效宝贝 编辑:程序博客网 时间:2024/04/30 06:13

http://blog.csdn.net/Jerry_BJ/archive/2010/06/06/5650683.aspx

 

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Style>
        Alert {
         /**通过buttonStyleName样式自定义Alert显示的按钮风格**/
            buttonStyleName: myCustomButtonStyleName;
            /**通过messageStyleName样式自定义Alert显示内容风格 **/
            messageStyleName: myCustomMessageStyleName;
   /**通过titleStyleName样式自定义Alert显示标题**/
    titleStyleName: myCustomTitleStyleName;
    /**通过backgroundAlpha, backgroundColor, borderAlpha和borderColor样式给Alert对话框设置背景颜色 **/
    backgroundAlpha: 0.3;
            backgroundColor: red;
            borderAlpha: 0.3;
            borderColor: red;
            dropShadowEnabled: false;
            creationCompleteEffect: myEffect;

        }
 
        .myCustomButtonStyleName {
            color: red;
            cornerRadius: 12;
            fontFamily: myComicSansMS;
            fontSize: 10;
            fontWeight: normal;
            textDecoration: underline;
            themeColor: red;
        }
       
          .myCustomMessageStyleName {
            color: haloOrange;
            fontFamily: myComicSansMS;
            fontSize: 10;
            fontWeight: normal;
        }
       
         .myCustomTitleStyleName {
            color: haloOrange;
            fontFamily: myComicSansMS;
            fontSize: 16;
            fontWeight: normal;
        }


</mx:Style>

<mx:Script>
        <![CDATA[
            import mx.controls.Alert;
 
            private var alert:Alert;
           
            [Embed(source="1.png")]
            private var BulletCritical:Class;
 
            [Embed(source="1.png")]
            private var IconCritical:Class;

 
            private function init():void {
                var myMessage:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit./nDonec tincidunt sollicitudin sem.";
                var myTitle:String = "The quick brown fox jumped over the lazy dog";
//                alert = Alert.show(myMessage, myTitle);
    /**Flex中如何利用titleIcon和iconClass属性给Alert添加Icon图标的例子 **/
                alert = Alert.show(myMessage, myTitle, Alert.YES|Alert.NO, null, null, IconCritical);
                alert.titleIcon = BulletCritical;
                //改变默认可选按钮的显示标签和按钮宽度。  
//     Alert.buttonWidth = 100;  
//     Alert.yesLabel = "确定";  
//     Alert.noLabel = "否";  
//     Alert.cancelLabel = "取消";  


            }
        ]]>
    </mx:Script>
 
  <mx:Sequence id="myEffect">
        <mx:Parallel>
            <mx:Zoom />
            <mx:Fade />
        </mx:Parallel>
        <mx:Rotate />
    </mx:Sequence>

 
  <mx:Button label="Launch alert" click="init();" />
</mx:Application>

 

--------------------------------------------------------------------------------------

 

 

package
{
 import flash.display.DisplayObject;
 
 import mx.controls.Alert;
 import mx.managers.PopUpManager;
 import flash.events.Event;
 
 public class AlertUtil
 {
  public function AlertUtil()
  {
  }
  
  public static function Prompt(msg:String,parent:DisplayObject):void{
     var alert:Alert = new Alert();
     alert.setStyle("messageStyleName","AlertMessage");
     alert.setStyle("titleStyleName","AlertTitle");
     alert.title = "提示";
     alert.text = msg;
     PopUpManager.addPopUp(alert,parent,true);
     PopUpManager.centerPopUp(alert);
   }
  
   public static function Confirm(msg:String,parent:DisplayObject,closeHandler:Function){
     var alert:Alert = new Alert();
     alert.setStyle("messageStyleName","AlertMessage");
     alert.setStyle("titleStyleName","AlertTitle");
     alert.title = "操作确认";
     alert.text = msg;
   alert.addEventListener(Event.CLOSE,closeHandler);
   alert.buttonFlags = Alert.OK | Alert.CANCEL;
   alert.defaultButtonFlag = Alert.OK;
   PopUpManager.addPopUp(alert,parent,true);
   PopUpManager.centerPopUp(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.events.CloseEvent;
   
   private function alt():void{
    
    AlertUtil.Confirm("hello",this,aa);
//    AlertUtil.Prompt("aaaaa",this);
   }
     
     
   private function aa(event:CloseEvent):void{
    
   }
  ]]>
 </mx:Script>
 
 <mx:Button label="点击" click="alt()" />
</mx:Application>

 

 

 

 --------------------------------------------------------------------

 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white"
  6.         creationComplete="showAlert()"
  7.         applicationComplete="init()">
  8.  
  9.     <!-- Used by the ApplicationControlBar control. -->
  10.     <mx:String id="fileName" />
  11.     <mx:String id="fileSize" />
  12.  
  13.     <!-- Used by the Alert control. -->
  14.     <mx:String id="message">The quick brown fox jumped over the lazy dog.
  15.  
  16. The quick brown fox jumped over the lazy dog.</mx:String>
  17.     <mx:String id="title">The quick brown fox jumped over the lazy dog?</mx:String>
  18.  
  19.     <mx:Script>
  20.         <![CDATA[
  21.             import mx.controls.Alert;
  22.  
  23.             private var a:Alert;
  24.  
  25.             private function init():void {
  26.                 var appInfo:LoaderInfo = Application.application.loaderInfo;
  27.                 /* Just grab the filename from the SWF URL. */
  28.                 fileName = (appInfo.url).split("/").pop();
  29.                 /* Convert bytes to kilobytes. */
  30.                 fileSize = (appInfo.bytesTotal / 1024).toFixed(2);
  31.             }
  32.  
  33.             private function showAlert():void {
  34.                 Alert.yesLabel = "Accept";
  35.                 Alert.noLabel = "Reject";
  36.                 Alert.buttonWidth = 120;
  37.  
  38.                 a = Alert.show(
  39.                         message,
  40.                         title,
  41.                         Alert.NO | Alert.YES
  42.                     );
  43.                 /* Make the Alert form's text non-selectable. */
  44.                 a.mx_internal::alertForm.mx_internal::textField.selectable = false;
  45.             }
  46.         ]]>
  47.     </mx:Script>
  48.  
  49.     <mx:Style>
  50.         @font-face{
  51.             src: url("./fonts/base02.ttf");
  52.             fontFamily: "Base02";
  53.         }
  54.  
  55.         Alert {
  56.             titleStyleName: "alertTitle";
  57.             messageStyleName: "alertMessage";
  58.             buttonStyleName: "alertButton";
  59.             dropShadowEnabled: true;
  60.             shadowDistance: 5;
  61.             shadowDirection: right;
  62.             cornerRadius: 0;
  63.             embedFonts: true;
  64.             fontFamily: Base02;
  65.         }
  66.  
  67.         .alertTitle {
  68.             letterSpacing: 0;
  69.             fontSize: 14;
  70.             color: red;
  71.         }
  72.  
  73.         .alertMessage {
  74.             letterSpacing: 0;
  75.             fontSize: 10;
  76.             fontWeight: normal;
  77.             color: black;
  78.         }
  79.  
  80.         .alertButton {
  81.             letterSpacing: 0;
  82.             fontSize: 11;
  83.             cornerRadius: 10;
  84.             fontWeight: normal;
  85.             textRollOverColor: white;
  86.             color: red;
  87.             skin: ClassReference(null);
  88.         }
  89.     </mx:Style>
  90.  
  91.     <!-- Display SWF name and file size. -->
  92.     <mx:ApplicationControlBar id="applicationControlBar" dock="true">
  93.         <mx:Label id="info" text="{fileName} ({fileSize}kb)" />
  94.     </mx:ApplicationControlBar>
  95.  
  96.     <!-- Click to launch Alert control. -->
  97.     <mx:Button label="Launch Alert" click="showAlert()" />
  98.  
  99. </mx:Application>