A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: animate Score Numbers climbing up

  1. #1
    Join Date
    Oct 2002
    new york

    animate Score Numbers climbing up

    hi. i know this should be easy, but my scripting sucks. i have a dynamic text field and i want the points to count up. say the user just finished a round and they got a score of $4000. i want the text to climb from $0 to $4000 in say 3 seconds. can someone point me to a movie or tutorial?

    thanking you kindly.

  2. #2
    Junior Member
    Join Date
    Jun 2011
    Ever heard of TweenMax ?


    This is what I'd do with it:

    Actionscript Code:
    import com.greensock.plugins.*;

    var v:Vector.<Number> = new Vector.<Number>(); //var for current state
    var end:Vector.<Number> = new Vector.<Number>(); //var for end state
    TweenMax.to(v, .5, { endVector:end, onUpdate:function(){_txt.text = Number(v).toFixed(2);} } );
    //toFixed(2) adds two numbers after the dot - 50.00

  3. #3
    Join Date
    May 2011
    Although TweenMax is free, it says I have to pay a license in order to use it in games I charge for. What if I don't? Can they detect games being sold using TweenMax not paying for the license?

  4. #4
    Join Date
    Oct 2002
    new york
    having problems with TweenMax and i cant believe theres not a simpler way to do this. isnt there a way to do something simple, with built in Tweens.

    myNum = 100;
    myNum = myNum + 100;
    if (myNum = 4000) then stop (adding).

    p.s. i know that my code is a joke, but ya know..

  5. #5
    Senior Member
    Join Date
    Jun 2003
    Kent, WA
    Tweening is actually pretty easy, you can do it without the TweenMax class. (Note this is untested code; I just wrote it up. May have compile errors.)

    import flash.utils.getTimer;
    scoreStart:Number = 0;
    scoreCurrent:Number = 0;
    scoreGoal:Number = 0;
    startTime:Number = 0;
    // ENTER_FRAME event handler
    function scoreInterpolate(event:Event)
    	var currentTime:Number = getTimer();
    	var durationTime:Number = 3000;
    	var t:Number = (currentTime - startTime) / durationTime;
    	if (t < 1)
    		// Not finished counting up; interpolate value
    		scoreCurrent = linearInterpolate(t, scoreStart, scoreGoal);
    		// At or exceeded the maximum time
    		//  Set the score to the target and terminate the event
    		scoreCurrent = scoreGoal;
    		removeEventListener(Event.ENTER_FRAME, scoreInterpolate)
    // Performs a linear interpolation between two values
    function linearInterpolate(t:Number, minVal:Number, maxVal:Number) : Number
    	return minVal + t * (maxVal - minVal);
    // Invokes an ENTER_FRAME event handler that will count up scoreCurrent to the provided goal
    function setScore(newScore:Number)
    	scoreStart = scoreCurrent;
    	scoreGoal = newScore;
    	startTime = getTimer();
    	addEventListener(Event.ENTER_FRAME, scoreInterpolate);
    This will perform a linear interpolation to count up. (ie the amount will grow by the same amount each frame) You could easily provide a function that will do exponential growth or anything else you wanted. (See here.)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center