0

我有一个 fla 文件和一个名为theAlarmClock. 时钟上的指针应该在移动,但之后Ctrl+Enter- 它们是空闲的。

package 
{
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;

public class theAlarmClock extends MovieClip
{
    var myDate:Date;
    var mySec:int;
    var myMin:int;
    var myHou:int;
    var myTimer:Timer = new Timer(1000);

    public function theAlarmClock()
    {

        myTimer.addEventListener(TimerEvent.TIMER, updateClock);
        myTimer.start();


        function updateClock(t:TimerEvent):void
        {
            myDate = new Date();
            mySec = myDate.seconds;
            myMin = myDate.minutes;
            myHou = myDate.hours;
            clockHandSeconds_mc.rotation = mySec * 6;
            clockHandMinutes_mc.rotation = myMin * 6;
            clockHandHours_mc.rotation = myHou * 30 + myMin * 0.5;
            trace("tick");


        }


    }
}

}
4

2 回答 2

0

Date您应该尝试使用-class的 get-functions 。

updateClock在您的函数中尝试此代码:

myDate = new Date();
mySec = myDate.getSeconds();
myMin = myDate.getMinutes();
myHou = myDate.getHours();
clockHandSeconds_mc.rotation = mySec * 6;
clockHandMinutes_mc.rotation = myMin * 6;
clockHandHours_mc.rotation = myHou * 30 + myMin * 0.5;
trace("tick");
于 2013-04-08T07:14:45.353 回答
0
package {


    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.sensors.Accelerometer;
    import flash.utils.Timer;

    public class ToolClass extends Sprite
    {
        private var myDate:Date;
        private var mySec:uint;
        private var myMin:uint;
        private var myHou:uint;
        private var myClock:Sprite;
        private var myHour:Shape;
        private var myMins:Shape;
        private var mySeco:Shape;

        private var myTimer:Timer=new Timer(1000);

    public function ToolClass()
    {
        drawClock();

        myTimer.addEventListener(TimerEvent.TIMER,updateClock);
        myTimer.start();
    }

    private function drawClock():void
    {
        myClock=new Sprite();
        myClock.graphics.lineStyle(0,0x000000,1);
        myClock.graphics.drawCircle(0,0,100);
        addChild(myClock);
        myClock.x=150;
        myClock.y=150;

        myHour=new Shape();
        myHour.graphics.lineStyle(5,0x00000,1);
        myHour.graphics.lineTo(0,-50);
        myClock.addChild(myHour);

        myMins=new Shape();
        myMins.graphics.lineStyle(2,0x000000,1);
        myMins.graphics.lineTo(0,-80);
        myClock.addChild(myMins);


        mySeco=new Shape();
        mySeco.graphics.lineStyle(1,0x000000,1);
        mySeco.graphics.lineTo(0,-80);
        myClock.addChild(mySeco);


    }
    public function getTime():void
    {
        myDate=new Date();

        myHou=myDate.hours;
        myMin=myDate.minutes;
        mySec=myDate.seconds;

    }
    private function updateClock(e:TimerEvent):void
    {
        getTime();
        myHour.rotation=myHou*30+30*myMin/60;
        myMins.rotation=myMin*6+6*mySec/60;
        mySeco.rotation=mySec*6;
        trace("tick");
    }
    }
}
于 2013-04-08T08:23:58.530 回答