views:

73

answers:

3

Currently using Tweener and wondering how I can tween a regular variable?

private var health:int = 100;

// And then somewhere else in the class
var amount:int = 50;

Tweener.addTween(this.health, {value:amount, 
                               onComplete:healCompleted, 
                               time:0.5, 
                               transition:"easeOutExpo"});

This is what I'm imagining and this sort of tweening works on other tweeners like GTween but this project is using Tweener.

The issue is with the "value" section, how can I put the value of the variable there?

The error I'm getting is

Property value not found on Number and there is no default value.

+1  A: 

You could try this:

//define a health Object
//anywhere in your code , instead of accessing the health integer, you 
//would access its value property. 
var health:Object = {value:100};

var amount:int = 50;

Tweener.addTween(this.health, {value:amount, 
                               onComplete:healCompleted, 
                               time:0.5, 
                               transition:"easeOutExpo"});

On the other hand , following the above logic, you could directly tween the variable by assigning it to a container Object with a value property.

PatrickS
Thanks, works great.
Ólafur Waage
+1  A: 

If health is a public property of your class it will work by simply adding your tween to the object that has the property, not to the property itself, as always with tweens:

Tweener.addTween(this, { health:amount, 
                         onComplete:healCompleted, 
                         time:0.5, 
                         transition:"easeOutExpo"});
grapefrukt
A: 

The first thing to do is make the health var public. That way Tweener can get the value of that variable, and get it too. Another way to achieve that is by making a getter and a setter for the health variable.

Then your tween would work when you use grapefrukt's example code.

frankhermes