views:

38

answers:

1

currently i'm tweening numbers with the Tween class by adding their value to an object's items array:

var tweenObject:Object = {value:20};
distanceTween = new Tween(tweenObject, "value", None.easeNone, 0, tweenObject.value, 5, true);

is this the most common, simple way to tween numbers with the Tween class?

i'm aware there are more simple solutions with other tween classes, but i'm only concerned with the default Tween class.

+3  A: 

Tween should work with any public variables of an object so you can define a public property on your class and have it work. By default variables on the timeline are public so you can just refer to those by name if you aren't inside a class. I also see no problem with what you are doing so if you are happy with it then don't worry too much about it.

So on the main timeline:

import fl.transitions.Tween;
import fl.transitions.easing.None;

var val:Number = 100;
var distanceTween:Tween = new Tween(this, "val", None.easeNone, 0, this.val, 5, true);

Or insides a class:

package
{
import fl.transitions.Tween;
import fl.transitions.easing.None;

import flash.display.Sprite;

public class ClassTweenTest extends Sprite
{
    public var val:Number;

    private var distanceTween:Tween

    public function ClassTweenTest()
    {
        val = 100;
        distanceTween = new Tween(this, "val", None.easeNone, 0, this.val, 5, true);
    }
}
}

I'd strongly urge you to learn to use a good tween engine like Tweener, TweenLite or gTween since they can give you a lot more flexibility within a much saner interface.

James Fassett
oh, of course! this is a much smarter solution. thanks again!
TheDarkInI1978