提示窗口类-Alert类和Confirm类

导读:
  
  [AS2]提示窗口类-Alert类和Confirm类
  演示效果
  Alert类
  /*** @link http://www.klstudio.com* @author Kinglong* @usage flash player 7* @version 0.1*/ import mx.transitions.*; import mx.transitions.easing.*; class as2.game.Alert extends MovieClip{ private static var __id:String = "alert_mc"; private static var __alert:MovieClip; private var __handler:Function; private var __top_mc:MovieClip; private var __box_mc:MovieClip; private var __bottom_mc:MovieClip; private var __close_btn:Button; private var __ok_btn:Button; private var __tween:Tween; private var __message_txt:TextField; private var __hit_btn:Button; private function Alert() { _xscale = _yscale = 100; __hit_btn.useHandCursor = false; __hit_btn._alpha = 80; __ok_btn.onRelease = __close_btn.onRelease = _closeHandler; __message_txt.autoSize = "Left"; _update(); _showTween(); } private function _setMessage(message:String):Void { __message_txt.text = message; _update(); } private function _setHandler(handler:Function):Void { __handler = handler; } private function _move(x:Number, y:Number):Void { _x = Math.floor(x); _y = Math.floor(y); __hit_btn._width = Stage.width; __hit_btn._height = Stage.height; __hit_btn._x = -_x; __hit_btn._y = -_y; } private function _update():Void { __hit_btn._width = 1; __hit_btn._height = 1; __hit_btn._x = 0; __hit_btn._y = 0; __box_mc._height = __message_txt._height + 15; __bottom_mc._y = __box_mc._y + __box_mc._height; __ok_btn._y = __bottom_mc._y - 15; _move((Stage.width - _width)/2,(Stage.height - _height)/2); } private function _close():Void { if (__handler != null) { __handler.apply(null, []); } this.removeMovieClip(); delete __alert; } private function _closeHandler():Void { _parent._closeTween(); } private function _showTween():Void { __tween = new Tween(this, "_alpha", Strong.easeOut, 50, 100, 1, true); __tween["state"] = "show"; __tween.onMotionFinished = _tweenHandler; } private function _closeTween():Void { __tween = new Tween(this, "_alpha", Strong.easeOut, 100, 0, 0.2, true); __tween["state"] = "close"; __ok_btn.enabled = __close_btn.enabled = false; __message_txt._visible = false; __tween.onMotionFinished = _tweenHandler; } private function _tweenHandler():Void { switch(this["state"]){ case "close": __alert._close(); break; case "show": break; } } public static function show(message:String, handler:Function):Void { if (__alert == null) { __alert = _root.attachMovie(__id, "alert", _root.getNextHighestDepth()); } __alert._setMessage(message); __alert._setHandler(handler); } private static function close():Void { if (__alert != null) { __alert._close(); } } }
  Confirm类
  /*** @link http://www.klstudio.com* @author Kinglong* @usage flash player 7* @version 0.1*/ import mx.transitions.*; import mx.transitions.easing.*; class as2.game.Confirm extends MovieClip{ private static var __id:String = "confirm_mc"; private static var __confirm:MovieClip; private var __handler:Function; private var __top_mc:MovieClip; private var __box_mc:MovieClip; private var __bottom_mc:MovieClip; private var __close_btn:Button; private var __ok_btn:Button; private var __cancel_btn:Button; private var __tween:Tween; private var __message_txt:TextField; private var __hit_btn:Button; private var __selected:Boolean; private function Confirm() { _xscale = _yscale = 100; __hit_btn._alpha = 80; __hit_btn.useHandCursor = false; __ok_btn.onRelease = _okHandler; __cancel_btn.onRelease = __close_btn.onRelease = _closeHandler; __message_txt.autoSize = "Left"; _update(); _showTween(); } private function _setMessage(message:String):Void { __message_txt.text = message; _update(); } private function _setHandler(handler:Function):Void { __handler = handler; } private function _move(x:Number, y:Number):Void { _x = Math.floor(x); _y = Math.floor(y); __hit_btn._width = Stage.width; __hit_btn._height = Stage.height; __hit_btn._x = -_x; __hit_btn._y = -_y; } private function _update():Void { __hit_btn._width = 1; __hit_btn._height = 1; __hit_btn._x = 0; __hit_btn._y = 0; __box_mc._height = __message_txt._height + 15; __bottom_mc._y = __box_mc._y + __box_mc._height; __cancel_btn._y = __ok_btn._y = __bottom_mc._y - 15; _move((Stage.width - _width)/2,(Stage.height - _height)/2); } private function _close():Void { if (__handler != null) { __handler.apply(null, [__selected]); } this.removeMovieClip(); delete __confirm; } private function _okHandler():Void { _parent.__selected = true; _parent._closeTween(); } private function _closeHandler():Void { _parent.__selected = false; _parent._closeTween(); } private function _showTween():Void { __tween = new Tween(this, "_alpha", Strong.easeOut, 50, 100, 1, true); __tween["state"] = "show"; __tween.onMotionFinished = _tweenHandler; } private function _closeTween():Void { __tween = new Tween(this, "_alpha", Strong.easeOut, 100, 0, 0.2, true); __tween["state"] = "close"; __cancel_btn.enabled = __ok_btn.enabled = __close_btn.enabled = false; __message_txt._visible = false; __tween.onMotionFinished = _tweenHandler; } private function _tweenHandler():Void { switch(this["state"]){ case "close": __confirm._close(); break; case "show": break; } } public static function show(message:String, handler:Function):Void { if (__confirm == null) { __confirm = _root.attachMovie(__id, "confirm", _root.getNextHighestDepth()); } __confirm._setMessage(message); __confirm._setHandler(handler); } private static function close():Void { if (__confirm != null) { __confirm._close(); } } }
  相关文件打包下载:http://www.klstudio.com/demo/test/win.rar(fla源文件需要用Flash CS3打开)

本文转自
http://www.klstudio.com/post/163.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值