Jump to content
Search Community

Tweeing a value, int [SOLVED]

yaure test
Moderator Tag

Recommended Posts

Just wondering how to tween an int or a Number variable, would it be something like endArray plugin or is there a more straight forward way?

 

o, and another question, if I'm using dynamicProps is there an easy way to update the time as well? would be nice also if it can call a function to recalculate the time every few seconds or so, something like an onUpdate but fires every few secs?

 

Thanks

Link to comment
Share on other sites

Just wondering how to tween an int or a Number variable, would it be something like endArray plugin or is there a more straight forward way?

 

Sure, you could use endArray but you don't need to. Just do something like:

 

var myVariable:Number = 0;
TweenLite.to(this, 2, {myVariable:100});

 

if I'm using dynamicProps is there an easy way to update the time as well? would be nice also if it can call a function to recalculate the time every few seconds or so, something like an onUpdate but fires every few secs?

 

You can adjust a tween's "duration" property anytime. Use a Timer or delayedCall() or whatever you want to trigger a function that adjusts it. You can even change the startTime of a tween.

Link to comment
Share on other sites

By the way is below the ideal way to tween an int/number value of a dynamic textfield?

 

public function updateNum(value:int):void { 
TweenLite.to(this, 0.5, { _num:value, onUpdate:txtUpdate } ); 
}	
private function txtUpdate():void { 
num_txt.text = String(_num); 
}

 

I saw somewhere in the forum you can use { text: } directly and set the mc to num_txt.text or something. But the textfield just shows NaN

 

TweenLite.to(num_txt, 0.5, { text:String(value) } );
TweenLite.to(num_txt, 0.5, { text:int(value) } ); 

 

Both above shows NaN

Link to comment
Share on other sites

Is your _num variable scoped as public or private/protected? It'd need to be public in order for TweenLite to be able to get/set it.

 

If you need to keep things private, you can use a generic object like this:

 

private var _numObj:Object = {num:0};
public function updateNum(value:int):void {
   TweenLite.to(_numObj, 0.5, { num:value, onUpdate:txtUpdate } );
}   
private function txtUpdate():void {
      num_txt.text = String(int(_numObj.num));
}

Link to comment
Share on other sites

oops, made a mistake in my wording

The top one works ok, I was gona ask whether the below should work or not, as I get NaN

 

TweenLite.to(num_txt, 0.5, { text:String(value) } );
TweenLite.to(num_txt, 0.5, { text:int(value) } ); 

Link to comment
Share on other sites

There must be something else going on in your code then. If "value" is indeed a number, then your second line should work fine assuming the starting value in your TextField is a number as well - if it's populated with a string like "myText" or something, then TweenLite won't be able to make that into a number to tween it.

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...