[Tweener] Getting tween target values

Zeh Fernando zeh at zehfernando.com
Mon Jul 28 10:42:22 PDT 2008


Hey Bradley,

> I've run into this issue before. Within this project there are several 
> places that would benefit from the added feature. In general I think it 
> would make applications simpler if it weren't required to store such 
> tween parameters in a variable every time we might need to retrieve them.

I admit this request is not something so out of this world. However, 
with its current architecture, Tweener doesn't allow you to access the 
tweenings already in place; you can have getTweens, but it's just to 
know if some property of some object is already tweening.

Giving your needs, and the ones that other people may have too, the best 
solution would be to have a way to access the tweening information 
*instance*, and then you could to changes to it. This is something I've 
kept on my mind for a while and something I was tackling with a 
moderately recent version of Tweener I was working on, but again, this 
is not something the current architecture has.

This is all just to say that yes, your request makes sense.

In the current version, for your specific case, the best solution would 
be adding a new function to Tweener to get the tweening information for 
a given object/property. Something like this (AS3):

public static function getTweenInfo (__obj:Object):TweenListObj {
	if (!Boolean(_tweenList)) return null;
	for (i:uint = 0; i<_tweenList.length; i++) {
		if (Boolean(_tweenList[i]) && _tweenList[i].scope == __obj) {
			return _tweenList[i];
		}
	}
	return null;
}

This returns a TweenListObj listing the tweening information of an 
object (see the class for more information). Specific properties 
(including their target values) are on a separate array. If you need that:

public static function getTweenPropertyInfo (__obj:Object, 
__prop:String):PropertyInfoObj {
	if (!Boolean(_tweenList)) return null;
	for (i:uint = 0; i<_tweenList.length; i++) {
		if (Boolean(_tweenList[i]) && _tweenList[i].scope == __obj && 
_tweenList[i].properties[__prop] != null) {
			return _tweenList[i].properties[__prop];
		}
	}
	return null;
}

Usage:

import caurina.transitions.PropertyInfoObj;
import caurina.transitions.Tweener;

Tweener.addTween(myobj, {x:10, time:1});

trace ("target value of x is "+getTweenPropertyInfo(myObj, 
"x").valueComplete);

Those classes - TweenListObj, and PropertyInfoObj - are pretty internal 
and it's likely they'll change a good bit in the future. However, if you 
build simple methods and functions on the Tweener class that handle 
them, there's a good amount of stuff you can add to it. You may even 
just add a simpler getTweenTargetValue() method directly if that works 
better.

public static function getTweenTargetValue (__obj:Object, 
__prop:String):Number {
	if (!Boolean(_tweenList)) return null;
	for (i:uint = 0; i<_tweenList.length; i++) {
		if (Boolean(_tweenList[i]) && _tweenList[i].scope == __obj && 
_tweenList[i].properties[__prop] != null) {
			return _tweenList[i].properties[__prop].valueComplete;
		}
	}
	return NaN;
}

So, something like this. I just wrote this without testing, but it 
should work unless I forgot something pretty obvious.

Zeh


More information about the Tweener mailing list