public class Main extends Sprite
{
var shi:Zhen = new Zhen(5,40,0x000000);
var fen:Zhen = new Zhen(3,80,0x444444);
var miao:Zhen = new Zhen(1,100,0xFF0000);
var time:Date;
public function Main()
{
init();
}
private function init()
{
var sprite:Sprite = new Sprite();
var biaopan:Circle = new Circle(0,0,135);
sprite.addChild(biaopan);
for(var i=0;i<12;i++)
{
var graduation_m:Xian = new Xian(15);
graduation_m.rotation = i*30;
sprite.addChild(graduation_m)
}
for(var j = 0; j < 60; j++)
{
var graduation:Xian = new Xian(10);
graduation.rotation = j*6;
sprite.addChild(graduation)
}
for(var t = 1; t <= 12; t++)
{
var number:Sprite = new Sprite();
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.text = String(t);
txt.x = -txt.width/2;
txt.y = -txt.height/2;
number.addChild(txt);
number.x = 275 + 110*Math.cos(30*Math.PI*t/180-Math.PI/2);
number.y = 200 + 110*Math.sin(30*Math.PI*t/180-Math.PI/2);
addChild(number);
}
sprite.addChild(shi);
sprite.addChild(fen);
sprite.addChild(miao);
sprite.x = 275;
sprite.y = 200;
addChild(sprite);
addEventListener(Event.ENTER_FRAME,Rotation);
}
private function Rotation(event:Event)
{
time = new Date();
miao.rotation = time.seconds*6;
fen.rotation =time.minutes*6;
shi.rotation = time.hours*30+time.minutes/2+time.seconds/120;
}
}
}
Circle
package
{
import flash.display.Sprite;
public class Circle extends Sprite
{
public function Circle(xp:int,yp:int,R:uint)
{
init(xp,yp,R);
}
private function init(xp:int,yp:int,R:uint)
{
graphics.lineStyle(3,0xFF0000);
graphics.drawCircle(xp,yp,R);
}
}
}
Xian
package
{
import flash.display.Sprite;
public class Xian extends Sprite
{
public function Xian(Length:uint)
{
init(Length);
}
private function init(Length:uint)
{
graphics.beginFill(0xFF0000);
graphics.drawRect(-1,-135,2,Length);
}
}
}
Zhen
package
{
import flash.display.Sprite;
public class Zhen extends Sprite
{
public function Zhen(thick:uint,Length:uint,color:uint)
{
init(thick,Length,color);
}
private function init(thick:uint,Length:uint,color:uint)
{
graphics.lineStyle(thick,color);
graphics.moveTo(0,0);
graphics.lineTo(0,-Length);
}
}
}
还望各位高手、大侠指正!作者: etthink 时间: 2011-10-8 19:33
很感谢有人发这个,不过这里人都不太了解As3.0所以从零开始比较好,加点注释作者: 红筹 时间: 2011-10-8 20:18