본문 바로가기

공부방/Flex

[Flex] 자동으로 닫히는 Alert

지정한 시간이 지나면 자동으로 close 되는 Alert 창입니다.
사용 방법은 CALERT.show('내용');
package AutoClose
{
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.controls.Alert;
	import mx.effects.Fade;
	import mx.effects.Move;
	import mx.effects.Parallel;
	import mx.effects.easing.Elastic;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;
	
	public class CALERT extends Alert
	{
		
		private static var alert:Alert;
		private static var alertTimer:Timer;
		private static var parellel:Parallel;
		private static var _fade:Fade;
		private static var _move:Move;
		
		public function CALERT()
		{
			super();
		}
		
		private static function init():void{
			_fade = new Fade;
			_fade.duration = 500;
			
			_move = new Move;
			_move.yFrom = 0;
			_move.easingFunction = Elastic.easeOut;
			_move.duration = 1000;
			
			parellel = new Parallel;
			parellel.addChild(_fade);
			parellel.addChild(_move);
			
		}
		
		public static function show(text:String = "", title:String = "알림", parent:Sprite = null ,delay:Number = 3000):Alert{
			init();
			alertTimer = new Timer(delay,1);
			alertTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeAlert);
			alertTimer.start();
			Alert.yesLabel = '확인';
			alert = Alert.show(text,title,Alert.YES,parent,alertClose);
			alert.isPopUp = false;
			alert.cacheAsBitmap = true;
			alert.setStyle('creationCompleteEffect',parellel);
			return alert;
		}
		
		private static function alertClose(event:CloseEvent):void
		{
			// TODO Auto Generated method stub
			alertTimer.stop();
			
		}
		
		private static function removeAlert(event:TimerEvent):void
		{
			// TODO Auto-generated method stub
			alertTimer.stop();
			PopUpManager.removePopUp(alert);
		}
		
		
	}
}

출처 : 
http://usanflower.egloos.com/3663363