·您当前的位置:首页 > 技术教程 >

[AS3]as3动态时钟as3制做时钟源代码实例

时间:2013-09-06 17:08cnblogs.com
[AS3]as3动态时钟as3制做时钟源代码实例,as3时钟,as3动态时钟

[AS3]as3动态时钟as3制做时钟源代码实例,as3时钟,as3动态时钟

  1. package 
  2. { 
  3.     import com.Box; 
  4.     import com.Xian; 
  5.      
  6.     import flash.display.Sprite; 
  7.     import flash.events.Event; 
  8.      
  9.     public class Main extends Sprite 
  10.     { 
  11.         //绘制三条指针 
  12.         private var shizhen:Xian = new Xian(25, 0x000000);        //时针 
  13.         private var fenzhen:Xian = new Xian(40, 0xff00ff);        //分针 
  14.         private var miaozhen:Xian = new Xian(55, 0xff0000);        //秒针 
  15.         private var shijian:Date; 
  16.          
  17.         public function Main():void 
  18.         { 
  19.             init(); 
  20.         } 
  21.          
  22.         private function init():void 
  23.         { 
  24.             var obj:Sprite = new Sprite(); 
  25.             obj.x = 250; 
  26.             obj.y = 180; 
  27.             this.addChild(obj); 
  28.              
  29.             //绘制表盘 
  30.             for(var i:uint = 0; i < 12; i++) 
  31.             { 
  32.                 var biaoshi:Box = new Box(); 
  33.                 biaoshi.rotation += i * 30;    //每生成一个,就在之前的角度上旋转30度 
  34.                 obj.addChild(biaoshi); 
  35.             } 
  36.              
  37.             obj.addChild(shizhen); 
  38.             obj.addChild(fenzhen); 
  39.             obj.addChild(miaozhen); 
  40.              
  41.             addEventListener(Event.ENTER_FRAME, dong); 
  42.         } 
  43.          
  44.         //cuplayer.com指针转动函数 
  45.         private function dong(evt:Event):void 
  46.         { 
  47.             shijian = new Date(); 
  48.              
  49.             //秒针的旋转角度算法:转一周360度,一分钟60秒,所以每一秒也就是旋转6度。 
  50.             miaozhen.rotation = shijian.seconds * 6; 
  51.              
  52.             //分针的旋转角度算法:和秒针同理,每一分钟也是旋转6度,再加上每一条针也要转动的角度 
  53.             fenzhen.rotation = shijian.minutes *6 + shijian.seconds * 0.1; 
  54.              
  55.             //cuplayer.com时针旋转角度算法: 
  56.             shizhen.rotation = shijian.hours * 30 + shijian.minutes * 0.5 + shijian.seconds * 0.0083; 
  57.  
  58.         } 
  59.     } 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器