Jump to content
Search Community

tween by round values

eOne test
Moderator Tag

Recommended Posts

As it is possible to use TweenLite/TweenMax on anything ( :D ) I am trying to tween text property of text field.

However, I need it to tween by round values eg. 0, 1, 2, 3 ... 100. For now I am getting 0.01, 0.02 ...

 

Is there some magic switch inside Tweenlite/Tweenmax lib that I've missed?

 

Thank you for help and for a such a great plugin.

Link to comment
Share on other sites

Yeah, that can be done. But just to clarify for others, you are going to be tweening a numeric variable / property that will displayed in a textfield.

 

here is some sample code that will do that for you:

 


import com.greensock.*;
import com.greensock.easing.*;

var score:Number = 0; //start value
var targetScore:Number = 20; //end value

TweenLite.to(this, 1, {score:targetScore, onUpdate:showScore, ease:Linear.easeNone});

function showScore(){
trace(score);
score_mc.score_txt.text = int(score); //you could also use Math.round()
}

 

 

 

basically you can tween any property, in this case score just like you would tween the alpha of a movieclip.

In order to visualize the change in value of the score property, you use an onUpdate callback to round your number and then place it in a textfield.

 

here is a video and source files for more explanation:

http://www.snorkl.tv/2010/09/how-to-tween-a-variable-with-flash-and-tweenlite/

 

here is a good reference for rounding to certain decimal places if you ever need it:

http://kb2.adobe.com/cps/155/tn_15542.html

 

Once you understand the basic concept check out the roundProps plugin for tweenlite/max in the plugin explorer:

http://www.greensock.com/tweenmax/

if using tweenMax, the code above could look like this:

TweenMax.to(this, 1, {score:targetScore, roundProps:["score"], onUpdate:showScore, ease:Linear.easeNone });

 

AND you wouldn't have to use int() or round() in the onUpdate function.

If using TweenLite, the roundProps plugin would have to be activated

 

import com.greensock.plugins.*;
TweenPlugin.activate([RoundPropsPlugin]);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...