flashactionscript-3tweener

How can I tween a Number?


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.


Solution

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