Flex: Utils
timedAlert : 일정 시간 후 종료되는 Alert창.#
참고1: http://warkyman.tistory.com/tag/Timer
참고2: http://flexexamples.blogspot.com/2007/12/flex-timed-alert-example.html
배운점#
-
setTimer( or setInterval ) 안에서 setTimer / setInterval 호출하면 메모리 leak?
-
NO
- Alert.show()는 생성하지 않고 setTimer만 중첩해서 호출해 봤는데 메모리릭이 없었다.
- 즉, setTimer()로 호출된 함수에서 setTimer()만 호출.
-
-
함수 안에서 함수를 선언할 수 있다!
- timerEventHandler() 함수는 timedAlertEx() 내부에서 변수처럼 생성됐으며, timedAlertEx()의 로컬변수를 접근할 수도 있었다.
소스코드#
public static function timedAlertEx( alert:Alert ):void {
//*
// setTimeout() 방식. N/G. 메모리 leak이 있다.
function timerEventHandler():void
{
mx.managers.PopUpManager.removePopUp( alert ); // Alert 제거
}
setTimeout( timerEventHandler, 500 );
/*/
// Timer() 방식. OK.
var myTimer:Timer;
function timerEventHandler(evt:TimerEvent):void
{
myTimer.stop();// 타이머 종료
mx.managers.PopUpManager.removePopUp( alert ); // Alert 제거
}
myTimer = new Timer(1100,1); // 타이머를 설정된 값에 맞게 Setting
myTimer.addEventListener(TimerEvent.TIMER, timerEventHandler ); // 이벤트핸들러 등록
myTimer.start(); // 타이머 시작
//*/
}
private function onInit():void {
setInterval( timedTask, 1000 );
}
private function timedTask():void {
Utils.timedAlertEx( Alert.show('second alert') );
}
History
Last edited on 02/24/2009 21:50 by 굴돌
Comments (0)