28Aug Flash Tween Proxy Theory
1,199 views
In the quest to find the most flexible, lightweight, and best performing tweening engine for Flash, I have come across a variety of packages including TweenMax/TweenLight, Go/HydroTween, and the new gTween. Currently, I swing towards TweenMax as the benchmarks have been favorable to it when dealing with hundreds of objects simeltanously. This aside though, I have been fascinated with Grant Skinner‘s gTween proxy idea. He creates a proxy object for a movieclip that allows automatic tweening on properties that the user would normally find and operate without a tween engine manually. See the below examples as they will make much more sense than a written explanation in this case.
Grant explains his proxy idea below:
Proxy Tweening
gTween provides a unique proxy property that allows you to work with tween destination values the same way you would work with them on the target object. The proxy object effectively “stands in” for your target object.
This simple example shows how you can use the proxy to move the target object 100 pixels to the right.
myTween.proxy.x += 100;
In the above example, the proxy will retrieve the x value from the target object (if it doesn’t already exist as a destination value in the tween), add 100, and set it back as a destination value for the tween.
This idea seemed very unique yet very straight forward for the person who implements the class. I have decided to write a wrapper class for TweenMax to do the same thing. Below is an example on how the client would use it for making an object tween across the screen, blur, and fade:
// box is a movieclip ID
var boxTween:TweenMaxProxy = new TweenMaxProxy(box);
boxTween.x+=100;
boxTween.y+=100;
boxTween.blur+=11;
boxTween.alpha-=0.3;
You can find a working copy here of my tween proxy for TweenMax: TweenMaxProxy. You can just drop this file into the /gs/ folder of TweenMax. As of right now, it only supports the properties x, y, alpha, and blur. If people find this helpful though, I can build this out more than it is.
While the syntax is a little bulky compared to the pure object syntax to make a tween with most tweening engines, this method is the only optimal way that I have derived to have a fast way for users to find and utilize tween properties without having to keep pulling docs up.
My TweenMaxProxy Class
TweenMax Link: http://blog.greensock.com/tweenmaxas3/
gTween Docs: http://www.gskinner.com/blog/archives/2008/08/gtween_a_new_tw.html#proxy
Auto-Generated Related Posts:

August 28th, 2008 at 8:04 pm
Hey, thanks for putting this out there!
You might want to consider adding a way to get the TweenMax instance that’s currently active inside your proxy so that folks can call pause(), resume(), reverse(), get the progress of the tween, etc.
Actually, I seriously considered adding a proxy to the core TweenMax class a little while ago, and actually built it out and it was working great (with any property), but then I realized that a setDestination() method would actually allow more flexibility because it can accept parameters. Normally, if you just update the destination values and the starting values stay the same, then you’ll see a sudden jump if the tween is in progress. However, TweenMax’s new setDestination() allows you to decide if you want that behavior or if you want TweenMax to adjust the start values so that the tween appears seamless (no sudden jump).
I believe Grant’s implementation causes the tween to start over again every time you change the property. So if you have a 3-second tween, and then 2.5 seconds into it, you change the destination value, it’ll tween for another 3 seconds and the easing will start over again as well. That’s not necessarily bad at all – just something to keep in mind. TweenMax’s setDestination() honors both the duration and the easing.
I released a big update to TweenMax today that adds a bunch of features including the setDestination() method. http://www.TweenMax.com
Thanks again for sharing, Jonathan!