Jump to content
Search Community

Increasing a variable

perloe test
Moderator Tag

Recommended Posts

I know this is probably a very basic question but I can't figure out how to simply increase the value of a variable over time.

 

So for example, if I have:

 

var counter:int = 0;

 

and I want to increase it to a new value of 10 over 5 seconds, how would I do that?

 

Thanks!

Link to comment
Share on other sites

Tweening a variable is no different than tweening the x property of a movie clip.

I understand how the concept can sound weird at first.

 

I have a tutorial and source files here:

http://www.snorkl.tv/2010/09/how-to-twe ... tweenlite/

 

an important thing to note is that while you are tweening the variable, you most likely want to display it somehow.

by using an onUpdate callback you can run a trace or update a textfield.

 

here is some sample code:

 

 

 

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

var score:Number = 0;
var targetScore:Number = 20;

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

function showScore(){
trace(score);
score_mc.score_txt.text = int(score);
}

Link to comment
Share on other sites

When I use the example before I get the error #1069:

Property score not found for "ClassX"

 

What am I doing wrong ?

 

Here my Code:

package
{
import com.greensock.TweenLite;

import flash.display.Sprite;

public class TweenTest extends Sprite
{
	private var _test:Number = 10;

	public function TweenTest()
	{
		TweenLite.to(this,1,{_test:200});
	}
}
}

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