public class Kclock extends Sprite { public var ticker:Timer;
public function Kclock() { this.drawFace(); this.drawHand(); this.update(); this.ticker = new Timer(1000); this.ticker.addEventListener(TimerEvent.TIMER, onTick); this.ticker.start(); }
private function drawFace():void{ var face:Face = new Face(); face.x = 150; face.y = 150; face.name = "face"; this.addChild(face); }
private function drawHand():void{ var sec:SecondHand = new SecondHand(); sec.x = 150; sec.y = 150; sec.name = "sec"; this.addChild(sec); var min:MinuteHand = new MinuteHand(); min.x = 150; min.y = 150; min.name = "min"; this.addChild(min); var hou:HourHand = new HourHand(); hou.x = 150; hou.y = 150; hou.name = "hou"; this.addChild(hou); var cen:Center = new Center(); cen.x = 150; cen.y = 150; cen.name = "cen"; this.addChild(cen); }
public function onTick(evt:TimerEvent):void{ this.update(); }
private function update():void{ var today:Date = new Date(); var len:uint = this.numChildren; for(var i:uint = 0;i<len;i++){ var clild:Sprite = this.getChildAt(i) as Sprite; switch(clild.name){ case "sec": clild.rotation = today.getSeconds()*6; break; case "min": clild.rotation = today.getMinutes()*6; break; case "hou": clild.rotation = (today.getHours() * 30) + (today.getMinutes() * 0.5); break; } } } } }