文王武帅

模拟时钟

    下面是一个模拟时钟的例子:

 

var second:uint;
var minute:uint;
var hour:uint;
var myDate:Date=new Date();
secondHand.rotation=myDate.getSeconds()*6;
minuteHand.rotation=myDate.getMinutes()*6+myDate.getSeconds()*6/360*6;
hourHand.rotation=myDate.getHours()*30+myDate.getMinutes()*6/360*30;
var timer:Timer=new Timer(800);
timer.start();
timer.addEventListener(TimerEvent.TIMER,updateTime);
function updateTime(e:TimerEvent):void {
	var myDate:Date=new Date();
	secondHand.rotation=myDate.getSeconds()*6;
	minuteHand.rotation=myDate.getMinutes()*6+myDate.getSeconds()*6/360*6;
	hourHand.rotation=myDate.getHours()*30+myDate.getMinutes()*6/360*30;
}
btnChanged.addEventListener(MouseEvent.CLICK,changeHandler);
function changeHandler(e:MouseEvent):void {
	timer.reset();
	second=uint(txtSecond.text);
	minute=uint(txtMinute.text);
	hour=uint(txtHour.text);
	secondHand.rotation=second*6;
	minuteHand.rotation=minute*6+second*6/360*6;
	hourHand.rotation=hour*30+minute/2;
	changedTimer.start();
}
var changedTimer:Timer=new Timer(1000);
changedTimer.addEventListener(TimerEvent.TIMER,changedTimerHandler);
function changedTimerHandler(e:TimerEvent):void {
	second++;
	if (second==60) {
		second=0;
		minute++;
		if (minute==60) {
			minute=0;
			hour++;
			if (hour==12) {
				hour=0;
			}
		}
	}
	secondHand.rotation=second*6;
	minuteHand.rotation=minute*6+second/10;
	hourHand.rotation=hour*30+minute/2;
}
btnBack.addEventListener(MouseEvent.CLICK,backHandler);
function backHandler(e:MouseEvent):void {
	var myDate:Date=new Date();
	secondHand.rotation=myDate.getSeconds()*6;
	minuteHand.rotation=myDate.getMinutes()*6+myDate.getSeconds()*6/360*6;
	hourHand.rotation=myDate.getHours()*30+myDate.getMinutes()*6/360*30;
	changedTimer.reset();
	timer.start();

}

  

 

posted on 2012-10-31 20:50  文王武帅  阅读(152)  评论(0)    收藏  举报

导航