tags:

views:

70

answers:

2

How do I make a loop to repeat my clock animation? I want to "replay" the animation. Need examples using loops and arguments.

alt text

ANALOG CLOCK EXAMPLE
Clock "ticks" and values can be changed.

var timer:Timer = new Timer(200, 36);//1000 = 1 sec
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
function onTimer(evt:TimerEvent):void {
watch.hand.rotation +=5;
}

I WANT EXAMPLE TO
Play animation from 1:00 to 2:00 and keep repeating.
"out to lunch time"

play->go back->play again

+1  A: 

This may help. Arguments to make it repeat I can't help with http://www.developphp.com/Flash_tutorials/show_tutorial.php?tid=189

pixelGreaser
Thanks. Maybe my question is silly, but I want to understand the timer class better. The example you showed still doesn't have a "reset" or loop argument. Cheer, appreciate the link.
VideoDnd
+1  A: 

Either of these should work:

Infinite loop on timer:

var timer:Timer = new Timer(20);

timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();   
function onTimer($evt:TimerEvent):void {
    hand.rotation = 30 + timer.currentCount % 30;
}

Controlled loop on timer:

var timer:Timer = new Timer(20, 30);

timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, startAgain);

timer.start();

function startAgain($evt:TimerEvent):void {
    timer.reset();
    timer.start();
}

function onTimer($evt:TimerEvent):void {
    hand.rotation = 30 + timer.currentCount;
}

I like the second one myself. Problem with the first is that timer.currentCount will grow forever. In the second example, it only ever gets to 30.

sberry2A
Fantastic! The "timer.reset" is very useful. The values can be reset to achieve a "tick" or play smooth.
VideoDnd