Guest User

Untitled

a guest
May 12th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.geom.*;
  2.  
  3. var carregarImg01:Loader = new Loader();
  4. var enderecoImg01:URLRequest = new URLRequest("relogio.png");
  5. carregarImg01.load(enderecoImg01);
  6. addChild(carregarImg01);
  7.  
  8. var ponteiro_segundos:Sprite = new Sprite();
  9. ponteiro_segundos.graphics.lineStyle(2, 0x000000, 0.75);
  10. ponteiro_segundos.graphics.beginFill(0x000000);
  11. ponteiro_segundos.graphics.moveTo(200, 20);
  12. ponteiro_segundos.graphics.lineTo(200, 200);
  13. ponteiro_segundos.graphics.endFill();
  14.  
  15. this.addChild(ponteiro_segundos);
  16.  
  17. var ponteiro_minutos:Sprite = new Sprite();
  18. ponteiro_minutos.graphics.lineStyle(7, 0x00FF00, 0.75);
  19. ponteiro_minutos.graphics.beginFill(0x00FF00);
  20. ponteiro_minutos.graphics.moveTo(200, 50);
  21. ponteiro_minutos.graphics.lineTo(200, 200);
  22. ponteiro_minutos.graphics.endFill();
  23.  
  24. this.addChild(ponteiro_minutos);
  25.  
  26. var ponteiro_horas:Sprite = new Sprite();
  27. ponteiro_horas.graphics.lineStyle(7, 0xFF0000, 0.75);
  28. ponteiro_horas.graphics.beginFill(0xFF0000);
  29. ponteiro_horas.graphics.moveTo(200, 100);
  30. ponteiro_horas.graphics.lineTo(200, 200);
  31. ponteiro_horas.graphics.endFill();
  32.  
  33. this.addChild(ponteiro_horas);
  34.  
  35. var centro:Sprite = new Sprite();
  36. centro.graphics.lineStyle(0,0xFF0000);
  37. centro.graphics.beginFill(0xFF0000);
  38. centro.graphics.drawCircle(0,0,7);
  39. centro.graphics.endFill();
  40. centro.x = 200;
  41. centro.y = 200;
  42.  
  43. addChild(centro);
  44.  
  45. this.addEventListener(Event.ENTER_FRAME, dispara_relogio);
  46.  
  47. function dispara_relogio(e:Event):void {
  48.     // armazena data/hora atuais
  49.     var agora = new Date();
  50.     var horas = agora.getHours();
  51.     var minutos = agora.getMinutes();
  52.     var segundos = agora.getSeconds();
  53.    
  54.     // converte a hora de 24h para 12h
  55.     if (horas > 12){
  56.         horas -= 12;
  57.     }
  58.    
  59.     // determina o ângulo dos ponteiros
  60.     var anguloHoras = 360*horas/12;
  61.     var anguloMinutos = 360*minutos/60;
  62.     var anguloSegundos = 360*segundos/60;
  63.    
  64.     // configura o ângulo dos ponteiros
  65.     ponteiro_horas.rotation = anguloHoras;
  66.     ponteiro_minutos.rotation = anguloMinutos;
  67.     ponteiro_segundos.rotation = anguloSegundos;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment