Jan 24

Tweening a MovieClip’s timeline using TweenLite

Category: Banner Tools, AS2

VIEW EXAMPLE
DOWNLOAD SOURCE

If you do alot of banners or work on projects with small filesize constraints, you should be hip to TweenLite written by Jack Doyle. This is a powerful Object Tweening engine that is incredibly small in file size (about 2.5K or so). Other Tweening Engines such as Caurina Tweener are a whopping 10K. That is alot of resources! One thing that TweenLite does not natively have which we at ICG need on a frequent basis is the ability to tween the timeline of a MovieClip. The reason TweenLite doesnt have this feature is because it’s original purpose is to be small in filesize and not bloated by excessive bells and whistles. The following is a workaround without changing Jack’s source files:

*DISCLAIMER: The following modification is using TweenLite VERSION: 5.8, it may not work with future versions of TweenLite.

 

//======================================================

 

import gs.TweenLite;
class gs.TweenLiteEnhanced {
public static function to ($obj:Object, $time:Number, $params:Object):Void {
if ($params._frame) {
$obj._frame = $obj._currentframe;
$params.onUpdateNew = $params.onUpdate;
$obj.onUpdate = function () {
$obj.gotoAndStop (Math.ceil ($obj._frame));
$params.onUpdateNew ();
};
$params.onUpdate = $obj.onUpdate;
}
TweenLite.to ($obj,$time,$params);
}
}

 

//======================================================

USE:
TweenLiteEnhanced.to(mcBox, 5, { _frame:300})
// mcBox is the name of the MovieClip

 

It works by injecting a function into the MovieClip which runs a gotoAndStop to the current value of the custom _frame property. It gets called on every update (the “onUpdate()” method). It only adds about 300 bytes above the class. Try it out, let me know what you think.

4 Comments so far

  1. Aloysiusje April 6th, 2008 8:22 pm

    nice work, man

  2. Jack June 7th, 2008 3:25 pm

    Nice work, Andy.

    Just so everyone knows, recent versions of TweenLite have this capability built-in. Just tween the special “frame” property. www.TweenLite.com

    Cheers.

  3. Jack June 7th, 2008 3:25 pm

    I have no idea why I called you Andy, Charles :-)

    I’ve been up way too long.

  4. admin June 7th, 2008 3:42 pm

    LOL, I’ve been called alot of things in my life Jack. Thanks for the comment. I’ve been pushing everyone I know to use TweenLite and TweenMax btw.