티스토리 뷰
<?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="401" height="227" fontSize="12"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.utils.StringUtil;
private var tmrCurTimer : Timer;
private var tmrCnt : Timer;
private var intCount : int = 0;
private function initApp():void {
/* Timer 함수 끝에 0이면 무한으로 돈다. */
tmrCurTimer = new Timer(1 * 1000, 0);
tmrCurTimer.addEventListener(TimerEvent.TIMER, tmrCurTimer_timer);
tmrCurTimer.start();
tmrCurTimer_timer(null);
/* 타이머 */
tmrCnt = new Timer(1 * 1000, 0);
tmrCnt.addEventListener(TimerEvent.TIMER, tmrCnt_timer);
tmrCnt.addEventListener(TimerEvent.TIMER_COMPLETE, tmrCnt_timerComplete);
labHD.visible = false;
}
private function tmrCnt_timerComplete(event:TimerEvent):void {
txtMsg.text = "완료";
}
private function tmrCurTimer_timer(e:TimerEvent):void {
var dtCur : Date = new Date();
txtCurTime.text = getZeroFill(dtCur.getHours().toString(),2) + ":" +
getZeroFill(dtCur.getMinutes().toString(),2) + ":" +
getZeroFill(dtCur.getSeconds().toString(),2);
}
// 1 -> 01 ~ 9 -> 09
private function getZeroFill(strArg:String, intSize:int):String {
var strRet:String = "";
/* 공백제거 */
strRet = "000000000000000000" + StringUtil.trim(strArg);
/*
abcd -> substr(0,2) -> ab
abcd -> substr(2,2) -> cd
abcdefghijklmnopqrstuvwxyz -> substr(-2,2) -> yz
*/
strRet = strRet.substr((-1)*intSize, intSize);
return strRet;
}
private function btn_Click(event:MouseEvent):void {
if(event.target == btn10) {
addTime(10);
} else if(event.target == btn30) {
addTime(30);
}
}
private function addTime(intTime : int):void {
intCount += intTime;
txtTmr.text = intCount.toString();
}
// 중요...
private function tmrCnt_timer(event:TimerEvent):void {
addTime(-1);
txtMsg.text += "..";
if(txtMsg.text.length >= 10) {
txtMsg.text = "요리중";
}
}
private function btnStart_Click():void {
if(tmrCnt.running) return;
tmrCnt.reset();
if(labHD.visible) {
addTime(intCount);
labHD.visible = false;
}
tmrCnt.repeatCount = intCount;
txtMsg.text = "요리중";
tmrCnt.start();
}
private function btnCancel_Click():void {
txtTmr.text = "00"
tmrCnt.reset();
intCount = 0;
txtMsg.text = "대기중";
}
private function btnHD_Click(event:MouseEvent):void {
labHD.visible = !labHD.visible;
}
]]>
</mx:Script>
<mx:Label x="10" y="10" text="현재시간" fontWeight="bold"/>
<mx:TextInput x="71" y="8" id="txtCurTime" text="12:34:56" textAlign="center" width="89"/>
<mx:TextInput x="10" y="71" id="txtTmr" text="00" textAlign="right" width="122"/>
<mx:Button x="10" y="103" label="10초" id="btn10" click="btn_Click(event)"/>
<mx:Button x="75" y="103" label="30초" id="btn30" click="btn_Click(event)"/>
<mx:Button x="10" y="167" label="시작" width="122" id="btnStart" click="btnStart_Click()" height="39"/>
<mx:TextInput x="10" y="39" width="122" id="txtMsg" backgroundColor="#E90000" color="#FBF92B" text="대기중" textAlign="left"/>
<mx:Button x="75" y="135" label="중지" width="57" id="btnCancel" click="btnCancel_Click()"/>
<mx:Button x="10" y="135" label="해동" width="57" id="txtHD" click="btnHD_Click(event)"/>
<mx:Label x="140" y="41" text="★" id="labHD"/>
< /mx:Application>
'Language > Flex' 카테고리의 다른 글
[ Flex ][ Source ] Baindable | DataGrid (0) | 2015.11.29 |
---|---|
[ Flex ][ Source ] Alert - 내용수정 필요 (0) | 2015.11.29 |
[ Flex ][ Source ] ex08_03 : Button Event / MouseWheel 값 event.delta (0) | 2015.11.29 |
[ Flex ][ Source ] ex08_02 : Event / e.stopPropagation() (0) | 2015.11.29 |
[ Flex ][ Source ] ex08_01 : try / catch / finally (0) | 2015.11.29 |