• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>AS基础篇>FLASH类>文章内容
  • 提示窗口类-Alert类和Confirm类(as2.0)
  • 来源:kinglong's blog 作者:kinglong 2008-04-21 【
[AS2]提示窗口类-Alert类和Confirm类

演示效果
 
Alert类

  1. /**  
  2. * @link http://www.klstudio.com  
  3. * @author Kinglong  
  4. * @usage flash player 7  
  5. * @version 0.1  
  6. */  
  7.   
  8. import mx.transitions.*;   
  9. import mx.transitions.easing.*;   
  10.   
  11. class  as2.game.Alert extends MovieClip{   
  12.        
  13.     private static var __id:String = "alert_mc";   
  14.     private static var __alert:MovieClip;              
  15.        
  16.     private var __handler:Function;    
  17.     private var __top_mc:MovieClip;   
  18.     private var __box_mc:MovieClip;   
  19.     private var __bottom_mc:MovieClip;   
  20.     private var __close_btn:Button;   
  21.     private var __ok_btn:Button;   
  22.     private var __tween:Tween;   
  23.     private var __message_txt:TextField;   
  24.     private var __hit_btn:Button;   
  25.        
  26.     private function Alert() {                 
  27.         _xscale = _yscale = 100;       
  28.         __hit_btn.useHandCursor = false;   
  29.         __hit_btn._alpha = 80;         
  30.         __ok_btn.onRelease = __close_btn.onRelease = _closeHandler;    
  31.         __message_txt.autoSize = "Left";           
  32.         _update();             
  33.         _showTween();   
  34.     }   
  35.        
  36.     private function _setMessage(message:String):Void {   
  37.         __message_txt.text = message;   
  38.         _update();   
  39.     }   
  40.        
  41.     private function _setHandler(handler:Function):Void {   
  42.         __handler = handler;   
  43.     }   
  44.        
  45.     private function _move(x:Number, y:Number):Void {   
  46.         _x = Math.floor(x);   
  47.         _y = Math.floor(y);    
  48.            
  49.         __hit_btn._width = Stage.width;   
  50.         __hit_btn._height = Stage.height;   
  51.         __hit_btn._x = -_x;   
  52.         __hit_btn._y = -_y;   
  53.     }   
  54.        
  55.     private function _update():Void {   
  56.         __hit_btn._width = 1;   
  57.         __hit_btn._height = 1;   
  58.         __hit_btn._x = 0;   
  59.         __hit_btn._y = 0;   
  60.            
  61.         __box_mc._height = __message_txt._height + 15;         
  62.         __bottom_mc._y = __box_mc._y + __box_mc._height;   
  63.         __ok_btn._y = __bottom_mc._y - 15;   
  64.            
  65.         _move((Stage.width - _width)/2,(Stage.height - _height)/2);   
  66.     }   
  67.        
  68.     private function _close():Void {           
  69.         if (__handler != null) {   
  70.             __handler.apply(null, []);   
  71.         }   
  72.         this.removeMovieClip();   
  73.         delete __alert;   
  74.     }   
  75.        
  76.     private function _closeHandler():Void {   
  77.         _parent._closeTween();   
  78.     }   
  79.        
  80.     private function _showTween():Void {   
  81.         __tween = new Tween(this"_alpha", Strong.easeOut, 501001true);   
  82.         __tween["state"] = "show";   
  83.         __tween.onMotionFinished = _tweenHandler;   
  84.     }   
  85.        
  86.     private function _closeTween():Void {          
  87.         __tween = new Tween(this"_alpha", Strong.easeOut, 10000.2true);   
  88.         __tween["state"] = "close";   
  89.         __ok_btn.enabled = __close_btn.enabled = false;   
  90.         __message_txt._visible = false;   
  91.         __tween.onMotionFinished = _tweenHandler;   
  92.     }   
  93.        
  94.     private function _tweenHandler():Void {   
  95.         switch(this["state"]){   
  96.             case "close":                  
  97.                 __alert._close();   
  98.                 break;   
  99.             case "show":   
  100.                 break;   
  101.         }   
  102.     }   
  103.        
  104.        
  105.     public static function show(message:String, handler:Function):Void {   
  106.         if (__alert == null) {   
  107.             __alert = _root.attachMovie(__id, "alert", _root.getNextHighestDepth());   
  108.         }   
  109.         __alert._setMessage(message);   
  110.         __alert._setHandler(handler);   
  111.     }   
  112.        
  113.     private static function close():Void {   
  114.         if (__alert != null) {   
  115.             __alert._close();   
  116.         }   
  117.     }   
  118.        
  119. }  


Confirm类

  1. /**  
  2. * @link http://www.klstudio.com  
  3. * @author Kinglong  
  4. * @usage flash player 7  
  5. * @version 0.1  
  6. */  
  7.   
  8. import mx.transitions.*;   
  9. import mx.transitions.easing.*;   
  10.   
  11. class  as2.game.Confirm extends MovieClip{   
  12.        
  13.     private static var __id:String = "confirm_mc";   
  14.     private static var __confirm:MovieClip;            
  15.        
  16.     private var __handler:Function;    
  17.     private var __top_mc:MovieClip;   
  18.     private var __box_mc:MovieClip;   
  19.     private var __bottom_mc:MovieClip;   
  20.     private var __close_btn:Button;   
  21.     private var __ok_btn:Button;   
  22.     private var __cancel_btn:Button;   
  23.     private var __tween:Tween;   
  24.     private var __message_txt:TextField;   
  25.     private var __hit_btn:Button;   
  26.     private var __selected:Boolean;   
  27.        
  28.     private function Confirm() {                   
  29.         _xscale = _yscale = 100;       
  30.         __hit_btn._alpha = 80;   
  31.         __hit_btn.useHandCursor = false;   
  32.         __ok_btn.onRelease = _okHandler;       
  33.         __cancel_btn.onRelease = __close_btn.onRelease = _closeHandler;    
  34.         __message_txt.autoSize = "Left";           
  35.         _update();             
  36.         _showTween();   
  37.     }   
  38.        
  39.     private function _setMessage(message:String):Void {   
  40.         __message_txt.text = message;   
  41.         _update();   
  42.     }   
  43.        
  44.     private function _setHandler(handler:Function):Void {   
  45.         __handler = handler;   
  46.     }   
  47.        
  48.     private function _move(x:Number, y:Number):Void {   
  49.         _x = Math.floor(x);   
  50.         _y = Math.floor(y);    
  51.            
  52.         __hit_btn._width = Stage.width;   
  53.         __hit_btn._height = Stage.height;   
  54.         __hit_btn._x = -_x;   
  55.         __hit_btn._y = -_y;   
  56.     }   
  57.        
  58.     private function _update():Void {   
  59.         __hit_btn._width = 1;   
  60.         __hit_btn._height = 1;   
  61.         __hit_btn._x = 0;   
  62.         __hit_btn._y = 0;   
  63.            
  64.         __box_mc._height = __message_txt._height + 15;         
  65.         __bottom_mc._y = __box_mc._y + __box_mc._height;   
  66.         __cancel_btn._y = __ok_btn._y = __bottom_mc._y - 15;   
  67.            
  68.         _move((Stage.width - _width)/2,(Stage.height - _height)/2);   
  69.     }   
  70.        
  71.     private function _close():Void {   
  72.         if (__handler != null) {   
  73.             __handler.apply(null, [__selected]);   
  74.         }   
  75.         this.removeMovieClip();   
  76.         delete __confirm;   
  77.     }   
  78.        
  79.     private function _okHandler():Void {   
  80.         _parent.__selected = true;   
  81.         _parent._closeTween();   
  82.     }   
  83.        
  84.     private function _closeHandler():Void {   
  85.         _parent.__selected = false;   
  86.         _parent._closeTween();   
  87.     }   
  88.        
  89.     private function _showTween():Void {   
  90.         __tween = new Tween(this"_alpha", Strong.easeOut, 501001true);   
  91.         __tween["state"] = "show";   
  92.         __tween.onMotionFinished = _tweenHandler;   
  93.     }   
  94.        
  95.     private function _closeTween():Void {          
  96.         __tween = new Tween(this"_alpha", Strong.easeOut, 10000.2true);   
  97.         __tween["state"] = "close";   
  98.         __cancel_btn.enabled = __ok_btn.enabled = __close_btn.enabled = false;   
  99.         __message_txt._visible = false;   
  100.         __tween.onMotionFinished = _tweenHandler;   
  101.     }   
  102.        
  103.     private function _tweenHandler():Void {   
  104.         switch(this["state"]){   
  105.             case "close":                  
  106.                 __confirm._close();   
  107.                 break;   
  108.             case "show":   
  109.                 break;   
  110.         }   
  111.     }   
  112.        
  113.        
  114.     public static function show(message:String, handler:Function):Void {   
  115.         if (__confirm == null) {   
  116.             __confirm = _root.attachMovie(__id, "confirm", _root.getNextHighestDepth());   
  117.         }   
  118.         __confirm._setMessage(message);   
  119.         __confirm._setHandler(handler);   
  120.     }   
  121.        
  122.     private static function close():Void {   
  123.         if (__confirm != null) {   
  124.             __confirm._close();   
  125.         }   
  126.     }   
  127.        
  128. }  


相关文件打包下载:http://www.klstudio.com/demo/test/win.rar (fla源文件需要用Flash CS3打开)




上一篇:AS深度处理常用函数(as2.0)   下一篇:Cookie类(as3.0)
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)