import flash.geom.*;
var carregarImg01:Loader = new Loader();
var enderecoImg01:URLRequest = new URLRequest("relogio.png");
carregarImg01.load(enderecoImg01);
addChild(carregarImg01);
var ponteiro_segundos:Sprite = new Sprite();
ponteiro_segundos.graphics.lineStyle(2, 0x000000, 0.75);
ponteiro_segundos.graphics.beginFill(0x000000);
ponteiro_segundos.graphics.lineTo(0, -180);
ponteiro_segundos.x = 200;
ponteiro_segundos.y = 200;
ponteiro_segundos.graphics.endFill();
this.addChild(ponteiro_segundos);
var ponteiro_minutos:Sprite = new Sprite();
ponteiro_minutos.graphics.lineStyle(7, 0x00FF00, 0.75);
ponteiro_minutos.graphics.beginFill(0x00FF00);
ponteiro_minutos.graphics.lineTo(0, -180);
ponteiro_minutos.x = 200;
ponteiro_minutos.y = 200;
ponteiro_minutos.graphics.endFill();
this.addChild(ponteiro_minutos);
var ponteiro_horas:Sprite = new Sprite();
ponteiro_horas.graphics.lineStyle(7, 0xFF0000, 0.75);
ponteiro_horas.graphics.beginFill(0xFF0000);
ponteiro_horas.graphics.lineTo(0, -100);
ponteiro_horas.x = 200;
ponteiro_horas.y = 200;
ponteiro_horas.graphics.endFill();
this.addChild(ponteiro_horas);
var centro:Sprite = new Sprite();
centro.graphics.lineStyle(0,0xFF0000);
centro.graphics.beginFill(0xFF0000);
centro.graphics.drawCircle(0,0,7);
centro.graphics.endFill();
centro.x = 200;
centro.y = 200;
addChild(centro);
this.addEventListener(Event.ENTER_FRAME, dispara_relogio);
function dispara_relogio(e:Event):void {
// armazena data/hora atuais
var agora = new Date();
var horas = agora.getHours();
var minutos = agora.getMinutes();
var segundos = agora.getSeconds();
// converte a hora de 24h para 12h
if (horas > 12){
horas -= 12;
}
// determina o ângulo dos ponteiros
var anguloHoras = 360*horas/12;
var anguloMinutos = 360*minutos/60;
var anguloSegundos = 360*segundos/60;
// configura o ângulo dos ponteiros
ponteiro_horas.rotation = anguloHoras;
ponteiro_minutos.rotation = anguloMinutos;
ponteiro_segundos.rotation = anguloSegundos;
} |