본문 바로가기

OM

디지털 시계


digitalWatch.mxml====================================================================================

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="580" height="200" initialize="init()">
 <mx:Style>
  Application {
      backgroundColor: #ffffff;
  }
 </mx:Style>
 
 <mx:Script>
  <![CDATA[
   import flash.utils.*;
   import flash.events.*;
   
   private var yoil:Array;
   
   private function digit(_c:int):String
   {
    if(_c<10)
    {
     return "0" + _c.toString();
    }
    else{
     return _c.toString();
    }
   }
   
   private function init():void
   {
    yoil = new Array("Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat");
   
    var myTimer:Timer = new Timer(1000, 0);
    myTimer.addEventListener("timer", timerHandler);
    myTimer.start();
   }
   
   private function timerHandler(e:TimerEvent):void
   {
    var now:Date = new Date();
   
    txtMonth.text = digit(now.getMonth()+1);
    txtDate.text = digit(now.getDate());
    txtYoil.text = yoil[now.getDay()];
    txtMinute.text = digit(now.getMinutes());
    txtSecond.text = digit(now.getSeconds());
   
    var hour:int = now.getHours();
   
    if(hour>12)
    {
     txtHour.text = digit(hour-12);
     txtAmPm.text = "PM";
    }
    else{
     txtHour.text = digit(hour);
     txtAmPm.text = "AM";
    }
   }
  ]]>
 </mx:Script>
 
 <mx:Canvas x="10" y="10" width="560" height="180" borderStyle="solid" verticalScrollPolicy="off" horizontalScrollPolicy="off">
  <mx:Text x="207.5" y="68" fontSize="90" id="txtAmPm"/>
  <mx:Text x="367" y="92" fontSize="20" id="txtMonth"/>
  <mx:Label x="406" y="92" fontSize="20" text="."/>
  <mx:Text x="434" y="92" fontSize="20" id="txtDate"/>
  <mx:Label x="475" y="92" fontSize="20" text="."/>
  <mx:Text x="503" y="92" fontSize="20" id="txtYoil"/>
  <mx:Text x="365.5" y="131" fontSize="25" id="txtHour"/>
  <mx:Label x="410.5" y="131" fontSize="25" text=":"/>
  <mx:Text x="433.5" y="131" fontSize="25" id="txtMinute"/>
  <mx:Label x="478.5" y="131" fontSize="25" text=":"/>
  <mx:Text x="501.5" y="131" fontSize="25" id="txtSecond"/>
 </mx:Canvas>
</mx:Application>

=====================================================================================================

'OM' 카테고리의 다른 글

영어 학습 컨텐츠  (0) 2008.02.22
keyUtil  (0) 2008.02.09
타자게임  (0) 2008.02.09
달력을 이용한 다이어리  (0) 2008.02.08
달력  (0) 2008.02.07
D-day 구하기 2  (0) 2008.02.07
D-day 구하기 1  (0) 2008.02.05
아날로그 시계  (0) 2008.02.04
동영상 플레이어  (0) 2008.01.11