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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值