package com.csharper.utils { import flash.display.Sprite; import flash.events.TimerEvent; import flash.utils.Timer; import mx.controls.Alert; import mx.core.IFlexModuleFactory; import mx.events.CloseEvent; import mx.managers.PopUpManager; /** * @Description: 自动关闭弹窗 * @author csharper * @date 2014-04-10 上午10:00:06 */ public class FlashAlert { private var alrt:Alert; private var alrtTimer:Timer; private var text:String; private var title:String; private var flags:uint; private var parent:Sprite; private var time:Number; public function FlashAlert(text:String="", title:String="", flags:uint=4, parent:Sprite=null,time:Number=1000) { this.text=text; this.title=title; this.flags=flags; this.parent=parent; this.time=time; this.init(); } private function init():void { alrtTimer = new Timer(time, 1); alrtTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeAlert); } public function showAlert():void { alrt = Alert.show(text, title, flags, parent, alrt_close); alrtTimer.reset(); alrtTimer.start(); } private function alrt_close(evt:CloseEvent):void { alrtTimer.stop(); } private function removeAlert(evt:TimerEvent):void { PopUpManager.removePopUp(alrt); } } }
测试代码如下:
var alert:FlashAlert=new FlashAlert("请输入关键字","提示",Alert.OK, this); alert.showAlert();