Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.moveTo(200, 20);
- ponteiro_segundos.graphics.lineTo(200, 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.moveTo(200, 50);
- ponteiro_minutos.graphics.lineTo(200, 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.moveTo(200, 100);
- ponteiro_horas.graphics.lineTo(200, 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment