calendar.mxml=======================================================================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="250" height="300" initialize="init()">
<mx:Style>
Application{
backgroundColor : #ffffff;
fontSize : 12;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Text;
private var month:Array;
private var now:Date;
private var time:Date;
private var startX:Number = 15;
private var startY:Number = 180;
private var spaceX:Number = 35;
private var spaceY:Number = 20;
private function clearAll():void
{
for(var i:int=1; i<32; i++)
{
var mc:DisplayObject = this.getChildByName(i.toString());
if(mc!=null)
{
this.removeChild(mc);
}
}
}
private function init():void
{
month = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
now = new Date();
time = new Date();
generateCalendar(time.getFullYear(), time.getMonth());
displayText();
}
private function generateCalendar(_year:Number, _month:Number):void
{
clearAll();
var temp:Date = new Date(_year, _month, 1);
var posY:Number = startY;
for(var i:int=1; i<32; i++)
{
temp.setDate(i);
if(temp.getMonth()==_month)
{
var mc:Text = new Text();
mc.width = 23;
mc.height = 18;
mc.setStyle("textAlign", "right");
if(temp.getFullYear()==now.getFullYear() && temp.getMonth()==now.getMonth() && temp.getDate()==now.getDate())
{
mc.setStyle("color", "#CC00FF");
}
else{
if(temp.getDay()==0)
{
mc.setStyle("color", "#ff0000");
}
else if(temp.getDay()==6){
mc.setStyle("color", "#0033FF");
}
else{
mc.setStyle("color", "#000000");
}
}
mc.x = startX + spaceX*temp.getDay();
if(temp.getDay()==0 && temp.getDate()!=1)
{
posY += spaceY;
}
mc.y = posY;
mc.text = i.toString();
mc.name = i.toString();
this.addChild(mc);
}
else{
break;
}
}
}
private function displayText():void
{
txtMonth.text = month[time.getMonth()];
txtYear.text = time.getFullYear().toString();
}
private function nextMonth():void
{
time.setMonth(time.getMonth()+1);
generateCalendar(time.getFullYear(), time.getMonth());
displayText();
}
private function prevMonth():void
{
time.setMonth(time.getMonth()-1);
generateCalendar(time.getFullYear(), time.getMonth());
displayText();
}
]]>
</mx:Script>
<mx:Label x="10" y="150" text="Sun" color="#ff0000"/>
<mx:Label x="43" y="150" text="Mon"/>
<mx:Label x="79" y="150" text="Tue"/>
<mx:Label x="112" y="150" text="Wed"/>
<mx:Label x="148" y="150" text="Thu"/>
<mx:Label x="187" y="150" text="Fri"/>
<mx:Label x="219" y="150" text="Sat" color="#0033FF"/>
<mx:HBox x="0" y="10" width="100%" horizontalAlign="right">
<mx:Text id="txtYear"/>
<mx:Text width="75" id="txtMonth"/>
</mx:HBox>
<mx:Button x="183" y="121" label="Next" buttonMode="true" click="nextMonth()"/>
<mx:Button x="10" y="121" label="Prev" buttonMode="true" click="prevMonth()"/>
</mx:Application>
=====================================================================================================
'OM' 카테고리의 다른 글
영어 학습 컨텐츠 (0) | 2008.02.22 |
---|---|
keyUtil (0) | 2008.02.09 |
타자게임 (0) | 2008.02.09 |
달력을 이용한 다이어리 (0) | 2008.02.08 |
D-day 구하기 2 (0) | 2008.02.07 |
D-day 구하기 1 (0) | 2008.02.05 |
아날로그 시계 (0) | 2008.02.04 |
디지털 시계 (0) | 2008.02.03 |
동영상 플레이어 (0) | 2008.01.11 |