views:

172

answers:

1

I'm creating a thermometer with the mercury animated as donations come in. I haven't touched flash in a long time, so be gentle.

How can I change the code below so the animation is faster without increasing the framerate?

var maxMercuryHeight = 192; // Mercury height at 100%
var currentDonations = 80; // Percentage of donations taken
var currentHeight = (currentDonations / 100) * maxMercuryHeight;

mercury.onEnterFrame = function()
{
    if(mercury._height < currentHeight) {
        mercury._height++;
    } else {
        delete mercury.onEnterFrame;
    }
}

trace(currentHeight);

Bonus question: How can I make the animation ease out so it starts fast and slows down at the end?

Thanks!

A: 
var speed = 0.4; // choose speed < 1 to suit    

if mercury._height < currentHeight {
mercury._height = mercury._height + 1 + speed*(currentHeight - mercury._height);
} else ...
Richard Inglis