Hello,
I have created Anolog Clock with tween between second which is working fine. But client now want that it should be first “Tween” from some point and then it should start analog clock. My problem is that when i give tween at starting it jerk between rotation before starting the actual clock as time is lag between tween animation and rotation of hand.
Can somebody have better logic to solve this?
Here is my code :
package{
import flash.display.*;
import flash.utils.*;
import flash.events.*;
import flash.text.*;
import caurina.transitions.Tweener;
public class Clock extends MovieClip
{
public function Clock()
{
addEventListener(Event.ADDED_TO_STAGE, init)
}
private function init(e:Event)
{
var currentTime:Date = new Date();
var dayOfWeek:Array = new Array("Sun ", "Mon ", "Tue ", "Wed ", "Thu ", "Fri ", "Sat ");
date_text.text = String(currentTime.getDate());
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var hours = currentTime.getHours() * 30 + currentTime.getMinutes() / 2;
Tweener.addTween(seconds_hand, {rotation:seconds * 6, time: 5});
Tweener.addTween(minutes_hand, {rotation:minutes * 6, time: 4});
Tweener.addTween(hours_hand, {rotation:hours, time: 2, onComplete: startTimer});
}
private function startTimer():void{
this.addEventListener (Event.ENTER_FRAME, runClock);
}
private function runClock (e:Event):void
{
var currentTime:Date = new Date();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var hours = currentTime.getHours() * 30 + currentTime.getMinutes() / 2;
var milliseconds = currentTime.getMilliseconds();
seconds_hand.rotation = seconds*6+(milliseconds/(1000/6));
minutes_hand.rotation = minutes*6 +(seconds/10);
hours_hand.rotation = hours;
}
}
}