views:

277

answers:

2

My meter looks great and the needle rotates in a loop. How do I add easing to it?

The meter is built from a timer event. I want the needle to bounce at the end. Rather than just adding a variable, I need some control of when it happens so I can adjust it with the animation.

alt text

WORKING CODE "Thxs to member"

var timer:Timer = new Timer(20, 30);//tick 200, 36<br>

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 { 
    watch.hand.rotation = 30 + timer.currentCount;//tick 5 
} 

FAILED ATTEMPT "needle's crazy, it's just suppose to bounce"

//the "tick" may mess up the effect

import fl.transitions.Tween;
import fl.transitions.easing.*;
var timer:Timer = new Timer(20, 30);//tick 200, 36
  var startValue:Number = watch.hand.rotation;
  var finishValue:Number = 33;//400
  var duration:Number = 222;//3
  var myTween:Tween = new Tween(watch.hand, "rotation", Elastic.easeOut, startValue, finishValue, duration, false);//true
  myTween.looping = true;
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 { 
    watch.hand.rotation = 30 + timer.currentCount;//tick 5
 //watch.x =+ 66;

} 

EXPERIMENT
My project will requires a higher understanding of timer events and tweening. If I can get this animation to do stuff, I think I can better understand how to pass function calls and set up events.

+1  A: 

I would use another tweening engine for this. Check out tweener or gtween. Makes things easier for animating and you can call functions when a tween has finished animating. You can create custom tweens and adjust how much bounce you want. There might be a way to do this with flash's built in tweening engine, but not sure how.

pfunc
+1  A: 

As @pfunc mentioned, this is going to be far easier to accomplish with a third party tweening library. It can be done with fl.transitions.Tween, but the chaining of tweens and onComplete handling is less than desirable.

As mentioned, check out one of these:

GTween

TweenLite

Tweener

All of these 3 have a very similar API (which is far better than Flash's built-in Tween - IMHO)

When I helped out with your original question about the Timer class, I did not realize that this is what you wanted to do. The Timer class is not a suitable choice for this problem as it is intended for events to be handled on consistent basis.

sberry2A
Ya, I can't recommend enough that people don't use the fl.transitions packages. We don't even allow it in our projects.
Tyler Egeto
@VideoDnd, I would actually give the check mark to @pfunc. After all, he had the same answer as me some 12 minutes before.
sberry2A
I'll go back to tweenlite maybe. My projects all involve loops, tweens, repetative motion that frame animation can't handle. Thanks.
VideoDnd