Archive for category TweenLite
Introduction to TimelineLite / TimelineMax
TimelineLite is a new library from the maker of TweenLite that enables you to group TweenLite instances (Tweens) to create the equivalent of the Flash Authoring Tool Timeline but in code. If you don’t know what TweenLite is head over to my tutorial on it first.
What is it for
The goal of this library is to give more power to the already powerful TweenLite library and to emulate some of the MovieClip’s functionalities. Once built, a TimelineLite instance will possess some methods that we’ve known for a long time: play(), stop(), gotoAndPlay(), etc. Three methods are used to create the timeline: append(), insert(), insertMultipple(). I prefer the insert method, it gives you more flexibility because you can set the time at which the Tween starts. The append() method will simply add your TweenLite instance at the end of the current timeline.
Here are some examples of how you would create a TimelineLite :
var myTimeline:TimelineLite = new TimelineLite(); //this will have 3 tween starting one after the one before is done myTimeline.append(new TweenLite(mc, 1, {x:200, y:100})); myTimeline.append(new TweenLite(mc, 0.5, {alpha:0})); myTimeline.append(new TweenLite(mc, 0.5, {alpha:1})); myTimeline.play(); //this one will have concurrent tweens a bit like layered tweens in the Flash Timeline myTimeline.insert(new TweenLite(mc, 1, {x:200, y:100}), 0); myTimeline.insert(new TweenLite(mc, 0.5, {alpha:0}), 0.75); myTimeline.insert(new TweenLite(mc, 0.5, {scaleX:2}), 1.25);
Some of the cool stuff you can do with is that inside a TimelineLite you can insert other TimelineLite instances. Also you can add Labels and tween using TweenLite to those labels. You can tween the time of the timeline as well as the progress. Here are examples of what I just mentioned:
var myTimeline:TimelineLite = new TimelineLite(); myTimeline.insert(new TweenLite(mc, 1, {x:200, y:100}), 0); myTimeline.insert(new TweenLite(mc, 0.5, {alpha:0}), 0.75); myTimeline.insert(new TweenLite(mc, 0.5, {scaleX:2}), 1); //Tween the timeline to any place in percent (from 0 to 1) TweenLite.to(myTimeline, 0.5, {progress:1}); //Tween to a particular second in time (from 0 to the duration of the timeline) TweenLite.to(myTimeline, 0.5, {time:0.75});
Its advantages
The major advantage that TimelineLite posesses over real timeline is the fact that it is dynamic. Meaning that you could make an function that takes a display object, that function would create an animation based on it and return a TimelineLite instance that you could use afterward. Then you could use that function to create the same animation on multiple display objects. Another example is that you could create animation based on what the user does, like you make him choose a number and you append that many instances on TweenLite in your TimelineLite (easy to do with traditionnal timeline too, but its just an example).
Its Max conterpart
As for the TweenLite library, TimelineLite has its Max equivalent, TimelineMax, which has more features like AS3 event listeners, repeat, repeatDelay, yoyo, addCallback(), removeCallback(), getActive(), etc. Just to tell you how good this library is, I have done a TimelineLite instance that tweened 25 display objects and 625 TweenLite instances and it worked perfectly fine, it wasn’t even slowing down.
ActionScript 3 TweenLite Basic Tutorial
If you have been following this blog for some time now you have witnessed my evolution in the use of tweening engines. I was first using the Tween classes from Adobe and made a tutorial about them. After that I found Tweener, which I liked a lot for it ease of use and its speed improvement so I modified my tutorial to explain Tweener. My new evolution in the field of tweening engine is TweenLite mostly because it is faster and lighter than Tweener. Since I did a tutorial on how to use the two previous tweening engines; it is only normal that I do one also for TweenLite.
Well the first thing you have to do is download the classes of TweenLite. After that you need to import the class in order to use it; here is the import statement:
1 2 | import gs.TweenLite; import fl.motion.easing.*; |
TweenLite as the name states is really light; it weights only 2k which is better than Tweener(10k). As you can see in the previous code I also imported the Adobe easing function. If you want to use easing, you will have to do that also which will had an additional 1k to the package.
TweenLite syntax is really similar to Tweener which is good since that was an advantage of using Tweener. Here is a simple tween using TweenLite:
1 | TweenLite.to (rectangle, 3, {x:300, ease:Linear.easeIn}); |
The difference from Tweener’s syntax is that the second parameter in TweenLite is duration(how much time in seconds will the tween last) in this case 3 seconds. So this line of code will make the displayObject rectangle move from its currents position to a new position where its x value will be 300 in 3 seconds.
The same way you did it with Tweener, you can also tween multiple properties with TweenLite, here is an example:
1 | TweenLite.to(rectangle, 1, {x:300, alpha:1, scaleX:1.5, scaleY:1.5, delay:2}); |
So this the rectangle will go to the x position 300, its alpha will raise to 100%, it will grow to 1.5 its original scale, all that in one second after a 2 second delay.
As you can see TweenLite offers all the advantages that Tweener offers with 2 more being light weight and being faster. I hope this tutorial will help you.
Using TweenLite in Preloaders
In the current project that I am doing, I need to do some Tweens in the preloader, nothing really fancy, just the habitual fade in / fade out ou move in / move out. I didn’t want to use Tweener because my preloader was only weighting 7k and using Tweener would have more than doubled the size of my preloader.
I was thinking at first about using the default Tweens classes from Adobe, but I decided to check out TweenLite. I was pretty amazed of what it can do. First it weights only 2k, but doesn’t include any easing functions, so if you want those you have to import the same classes as the Tween classes. If you use easing it adds 1k to the weight so it’s not too bad. So in total it’s only 1k more than the Tween classes.
Here is an example of code using TweenLite:
1 2 | import gs.TweenLite; TweenLite.to(mc, 1, {x:46, y:43}); |


