Flip clock showing time issue (animations invovled)
- by Hwang
I'm creating a flip clock (clock where you always see in airport), but I can't seems to get the time to show at the correct timing.
After the flip, then will see the number changing. But I want it to change before it flips.
Currently I'm not sure whether is the animation problem, or isit I have to do something else on the script. I've uploaded the FLA so that you could have a look on how I set up the flipping animation.
http://www.mediafire.com/?nzmymjgtntz
Below is the AS3 code:
package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class flipClock extends MovieClip {
private var clock:clockMC=new clockMC();
//seconds
private var secTop1=clock.second.top1.digit;
private var secTop2=clock.second.top2.digit;
private var secBot1=clock.second.bot1.digit;
private var secBot2=clock.second.bot2.digit;
private var seconds:Number;
private var minutes:Number;
private var hours:Number;
private var days:Number;
public function flipClock():void {
decrease();
addChild(clock);
}
private function decrease():void {
var countdownTimer:Timer=new Timer(1000);
//Adding an event listener to the timer object
countdownTimer.addEventListener(TimerEvent.TIMER,updateTime);
//Initializing timer object
countdownTimer.start();
}
private function updateTime(event:TimerEvent):void {
decreasTimerFunction();
updateSecond();
//updateMinute();
}
private function updateSecond():void {
clock.second.play();
secTop1.text=num2;
secTop2.text=num1;
if (num1<10) {
num1="0"+num1;
}
if (num2<10) {
num2="0"+num2;
}
if (num1==60) {
num1=0;
}
if (num2==60) {
num2=0;
}
secTop1.text=num1;
secTop2.text=num2;
//secBot1.text=num1;
//secBot2.text=num2;
}
private function decreasTimerFunction():void {
//Create a date object for Christmas Morning
var endTime:Date=new Date(2010,4,26,0,0,0,0);
//Current date object
var now:Date=new Date();
// Set the difference between the two date and times in milliseconds
var timeDiff:Number=endTime.getTime()-now.getTime();
seconds=Math.floor(timeDiff/1000);
minutes=Math.floor(seconds/60);
hours=Math.floor(minutes/60);
days=Math.floor(hours/24);
// Set the remainder of the division vars above
hours%=24;
minutes%=60;
seconds%=60;
}
}
}