电子时钟

==========onClock文档类========== 

package {
	import flash.display.Sprite;
	import flash.events.Event;
	public class onClock extends Sprite {
		var hourH:Clock_hand=new Clock_hand(25,0x000000);
		var minuteH:Clock_hand=new Clock_hand(40,0xff00ff);
		var secondH:Clock_hand=new Clock_hand(56,0xff0000);
		var currentTime:Date;
		public function onClock():void {
			init();
		}
		private function init():void {
			var biaopan:Sprite=new Sprite();
			biaopan.x=biaopan.y=240;
			addChild(biaopan);
			for (var i:uint=0; i<12; i++) {
				var biaoshi:Clock_rect=new Clock_rect();
				biaoshi.rotation+=i*30;
				biaopan.addChild(biaoshi);
			}
			biaopan.addChild(hourH);
			biaopan.addChild(minuteH);
			biaopan.addChild(secondH);
			addEventListener(Event.ENTER_FRAME,turn);
		}
		private function turn(evt:Event):void {
			currentTime=new Date();
			secondH.rotation=currentTime.seconds*6;
			minuteH.rotation=currentTime.minutes*6+currentTime.seconds*0.1;
			hourH.rotation=currentTime.hours*30+currentTime.minutes*0.5+currentTime.seconds*0.0083;
		}
	}
}

==========Clock_rect 12个小方块类==========

package {
	import flash.display.Shape;
	public class Clock_rect extends Shape {
		public function Clock_rect():void {
			init();
		}
		private function init():void {
			this.graphics.beginFill(0x54f687);
			this.graphics.drawRect(-3,-85,6,25);
			this.graphics.endFill();
		}
	}
}

==========Clock_hand指针类==========

package {
	import flash.display.Shape;
	public class Clock_hand extends Shape {
		public function Clock_hand(len:uint,color:uint):void {
			init(len,color);
		}
		private function init(len:uint,color:uint):void {
			this.graphics.lineStyle(2,color);
			this.graphics.moveTo(0,0);
			this.graphics.lineTo(0,len*-1);
			this.graphics.endFill();
		}
	}
}
原文地址:https://www.cnblogs.com/leon3286/p/1709406.html