In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

末日処理を入れてみた forked from: 万年カレンダー

万年カレンダー
5秒おきに翌月のカレンダーになります。
どの月も31日まであるんで誰かforkお願いします。

paqさんのネタ元はこれかぁ^^;
もっとシンプルに書きたいけど、とりあえず良いみたいです。
初期セットは大丈夫かな?...
Get Adobe Flash player
by Kay 06 Mar 2009
// forked from cDa's 万年カレンダー
/*
万年カレンダー
5秒おきに翌月のカレンダーになります。
どの月も31日まであるんで誰かforkお願いします。
*/
// paqさんのネタ元はこれかぁ^^;
// もっとシンプルに書きたいけど、とりあえず良いみたいです。
// 初期セットは大丈夫かな?...

package
{
	
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import caurina.transitions.Tweener;
	
	[SWF(width="400", height="300", backgroundColor="0xFFFFFF", frameRate="30")]

	public class Main extends MovieClip
	{
		private const CAL1:String="                      1  2  3  4  5  6  7\n";
		private const CAL2:String=" 1  2  3  4  5  6  7  8  9 10 11 12 13 14\n";
		private const CAL3:String=" 8  9 10 11 12 13 14 15 16 17 18 19 20 21\n";
		private const CAL4:String="15 16 17 18 19 20 21 22 23 24 25 26 27 28\n";
		private const CAL5:String="22 23 24 25 26 27 28 29 30 31\n";
		private const CAL6:String="29 30 31\n";
		
		private const CAL5_28:String="22 23 24 25 26 27 28\n";
		private const CAL6_28:String="\n";

		private const CAL5_29:String="22 23 24 25 26 27 28 29\n";
		private const CAL6_29:String="29\n";

		private const CAL5_30:String="22 23 24 25 26 27 28 29 30\n";
		private const CAL6_30:String="29 30\n";

		private var calW:uint;
		private var calH:uint;
		private var calBlockW:Number;
		private var calGoalX:Number;
		private var date_txt:TextField = new TextField();
		private var cal_txt:TextField = new TextField();
		private var day_mc:MovieClip = new MovieClip();
		private var tFormat:TextFormat = new TextFormat("_等幅", 16);
		private var calTimer:Timer=new Timer(5000);
		private var date:Date;
		
		
		public function Main():void
		{
			tFormat.leading=3;

			date_txt.defaultTextFormat = tFormat;
			date_txt.width = 400;
			date_txt.x = 50;
			date_txt.y = 50;
			
			cal_txt.defaultTextFormat = tFormat;
			cal_txt.text = CAL1 + CAL2 + CAL3 + CAL4 + CAL5 + CAL6;
			cal_txt.x = -400;
			cal_txt.y = 100;
			cal_txt.width = 400;
			cal_txt.height = 300;
			
			calW = cal_txt.textWidth+4;
			calH = cal_txt.textHeight+4;
			calBlockW = calW / 14;
			
			day_mc.graphics.beginFill(0xFFFFFF, 0.7);
			day_mc.graphics.drawRect(-50, 0, 50, calH);
			day_mc.graphics.drawRect(calW*0.5, 0, 400, calH);
			day_mc.graphics.beginFill(0xFFAAAA, 0.6);
			day_mc.graphics.drawRect(0, 0, calBlockW, calH);
			day_mc.graphics.beginFill(0xAAAAFF, 0.6);
			day_mc.graphics.drawRect(calW*6/14, 0, calBlockW, calH);
			day_mc.graphics.endFill();
			day_mc.x = 50;
			day_mc.y = 100;
			
			addChild(cal_txt);
			addChild(date_txt);
			addChild(day_mc);
			
			mvCal(new TimerEvent(TimerEvent.TIMER) );
			
			calTimer.addEventListener(TimerEvent.TIMER, mvCal);
			calTimer.start();
		}
		
		
		private function mvCal(tEvt:TimerEvent):void
		{
			if(date){	upDateGoal(date);	}
			else{
				var today:Date = new Date();
				today.date=1;
				upDateGoal( today );
			}
			Tweener.addTween( cal_txt, { x:calGoalX, time:1 } );
		}

		
		private function upDateGoal(prmDate:Date):void
		{
			var day:uint = prmDate.getDay();
			if(day==0){	calGoalX = 50;	}
			else{	calGoalX = 50-calBlockW * (7-day);	}
			date_txt.text = ""+prmDate.getFullYear()+" / "+(prmDate.getMonth()+1);
			
			var year:uint = prmDate.getFullYear();
			var month:uint = prmDate.getMonth()+1;
			if(month == 12){
				month = 0;
				year ++;
			}
			changeLastDate(prmDate);
			date = new Date(year, month, 1);
		}

		private function changeLastDate(lastDate:Date):void {
			lastDate.setMonth(lastDate.month+1,1);
			lastDate.setTime(lastDate.getTime()-60*60*24*1000);
			var calTxt:String = CAL1 + CAL2 + CAL3 + CAL4;
			switch(lastDate.date) {
				case 28:
					calTxt += CAL5_28 + CAL6_28;
                			break;
				case 29:
					calTxt += CAL5_29 + CAL6_29;
					break;
				case 30:
					calTxt += CAL5_30 + CAL6_30;
					break;
				default:
					calTxt += CAL5 + CAL6;
			}
			cal_txt.text = calTxt;
		}
		
	}
	
}