アナデジ時計
/**
* Copyright kazuyuki ( http://wonderfl.net/user/kazuyuki )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/wueN
*/
// forked from kazuyuki's flash on 2010-4-24
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.text.TextField;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.text.TextFormat;
public class FlashTest extends MovieClip {
public function FlashTest() {
// write as3 code here..
stage.addEventListener(Event.ENTER_FRAME,clock);
var _text:TextField = new TextField();
var tf:TextFormat = new TextFormat();
var centerX:Number = stage.stageWidth/2;
var centerY:Number = centerX;
tf.size = 20;
_text.width = stage.stageWidth;
_text.defaultTextFormat = tf;
var Days:Array =["日","月","火","水","木","金","土"];
var All:Array =["1","2","3","4","5","6","7","8","9","10","11","12"]
//それぞれの針を描画
var sec:drowRect = new drowRect(-1, 0, 2, 150, 0xffff00);
sec.x = sec.y =centerX;
var min:drowRect = new drowRect(-2, 0, 4, 100, 0xff0000);
min.x = min.y = centerX;
var hour:drowRect = new drowRect(-3, 0, 6, 50, 0x0000ff);
hour.x = hour.y = centerX;
var maru:drowCircle = new drowCircle(0, 0xffffff,5);
maru.x = maru.y = centerX;
var maru1:drowCircle = new drowCircle(0, 0xffffff,180);
maru1.x = maru1.y = centerX;
addChild(maru1);
var j:int=0;
for(var i:int = 0; i<=360; i += 30){
var timeText:TextField = new TextField();
var ttf:TextFormat = new TextFormat();
ttf.align ="center";
timeText.defaultTextFormat = ttf;
timeText.width = 20;
timeText.height = 20;
timeText.text = All[j];
timeText.x = 170*Math.cos((i-60)*Math.PI/180)+centerX - 10;
timeText.y = 170*Math.sin((i-60)*Math.PI/180)+centerY - 8;
addChild(timeText);
j += 1;
}
function clock(e:Event):void{
var now:Date = new Date();
var _year:Number = now.getFullYear();
var _month:Number = now.getMonth() + 1;
var _date:Number = now.getDate();
var _day:Number = now.getDay();
var _hour:Number = now.getHours();
var _min:Number = now.getMinutes();
var _sec:Number = now.getSeconds();
_text.text = _year + "年" + _month + "月" + _date + "日" + "(" + Days[_day] + ")" + _hour + ":" + _min + ":" + _sec;
sec.rotation = (360/60)*_sec + 180;
min.rotation = (360/60)*_min + 180;
hour.rotation = (360/12)*_hour + 180;
addChild(min);
addChild(sec);
addChild(hour);
addChild(_text);
addChild(maru);
}
}
}
}
import flash.display.Sprite;
class drowRect extends Sprite{
public function drowRect(tX:Number, tY:Number, dw:Number, dh:Number, color:Number){
graphics.beginFill(color);
graphics.drawRect(tX, tY, dw, dh);
graphics.endFill();
}
}
import flash.display.Sprite;
class drowCircle extends Sprite{
public function drowCircle(linecolor:Number, color:Number, r:Number){
graphics.lineStyle(linecolor);
graphics.beginFill(color);
graphics.drawCircle(-(this.width/2),-(this.height/2),r);
graphics.endFill();
}
}