`

flex 写的时钟

    博客分类:
  • flex
阅读更多
俗话说,做一天和尚,撞一天钟,我就用flex做了个简单的钟表,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.utils.setInterval;
import mx.effects.easing.*;

[Bindable]
            public var second:int=0;
           
             [Bindable]
            public var hourse:int=0;
           
             [Bindable]
            public var minu:int=0;
           
            private var secondCount:int=1;
            private var minuCount:int=1;
            private var hourseCount:int=1;
private function init():void
            {
            initClock();
            setInterval(rotateImageSecond,1000);
            }
           
            private function initClock():void
            {
            var d:Date=new Date();
            var currenthourse:Number=d.getHours();
            var currentminu:Number=d.getMinutes();
            if(currenthourse>12)
            {
              hourse=30*(currenthourse-12);
            }else
            {
            hourse=30*currenthourse;
            }
            hourse+=2.5*(currentminu/5);
            minuCount=currentminu%5;
            if(minuCount==0)minuCount=1;
           
            minu=6*currentminu;
           
            rotateMinu_id.end();
                rotateMinu_id.play();
               
                rotateHourse_id.end();
                rotateHourse_id.play();
            }
             private function rotateImageSecond():void {
            if(6*secondCount==360)
                {
                second=0;
                  rotateImageMinu();
   
                  secondCount=1;
                }else
                {
                secondCount++;
                }
                rotateSecond_id.end();
                second +=6;
                rotateSecond_id.play();
               
            }
            private var minuCount2:int=1;
             private function rotateImageMinu():void {
             if(6*minuCount==30)
                {
               
                  rotateImageHourse();
                  minuCount=1;
                }else
                {
                minuCount++;
                }
                if(6*minuCount2==360)
                {
                minu=0;
                minuCount2=1;
                }else
                {
                minuCount2++;
                }
               
                rotateMinu_id.end();
                minu +=6;
                rotateMinu_id.play();
            }
       
            private function rotateImageHourse():void {
            
             if(2.5*hourseCount==360)
             {
             hourse=0;
             hourseCount=1;
             }else
             {
             hourseCount++;
             }
                rotateHourse_id.end();
                hourse +=2.5;
                rotateHourse_id.play();
            }
]]>
</mx:Script>
<mx:Rotate id="rotateSecond_id" angleFrom="{second-6}" angleTo="{second}" target="{imageSecond}" />
    <mx:Rotate id="rotateHourse_id" angleFrom="{hourse-2.5}" angleTo="{hourse}" target="{imageHourse}"/>
    <mx:Rotate id="rotateMinu_id" angleFrom="{minu-6}" angleTo="{minu}" target="{imageMinu}"/>
   
                <mx:Canvas width="100%" height="100%" verticalScrollPolicy="off" horizontalScrollPolicy="off">
                        <mx:VBox x="0" y="0" height="100%" width="100%" verticalGap="0">
                                <mx:Canvas width="100%" height="100%" verticalScrollPolicy="off" horizontalScrollPolicy="off" backgroundColor="#FFFFFF">
                                <mx:Image x="129" y="23" width="218" height="208" source="images/clock.gif"/>
                                        <mx:Image height="170" width="2" source="images/second.gif" id="imageSecond" x="231" y="40"/>
                                        <mx:Image height="150" width="4" source="images/minu.gif" id="imageMinu" x="230" y="50"/>
                                        <mx:Image height="95" width="6" source="images/hourse.gif" id="imageHourse" x="229" y="77"/>
                                       
                                       
                                </mx:Canvas>
                        </mx:VBox>
                </mx:Canvas>
      
</mx:Application>
  • 大小: 16.6 KB
分享到:
评论
1 楼 zlbdexiaohao 2015-07-23  
   

相关推荐

Global site tag (gtag.js) - Google Analytics