Controlling a timeline with TimelineLite
In the last lecture, every single animation had a unique timeline. By using TimelineLite we are creating a shared timeline. In this lesson, we will create our first timeline and add three animations into it.
Video Transcript
00:00In the last lesson, we met timelines for the first time or the concept of timelines in the first time and seen the difference between frames and seconds.
00:09It's time for us to go back into our code and create our own timeline so we can then put all our animations inside of one timeline and control it.
00:17And that's exactly what we're going to do using the add method.
00:21So let's jump into it, the timeline light and the add method.
00:24So let's jump into it and see how that works.
00:27In essence, we've seen timelines already.
00:29We took a peek at them when we were looking at our flash timeline and really our animations that we were creating have their own timelines.
00:37But literally what's going on right now is each of them is running on their own timeline.
00:42So we have your one timeline and another timeline and another timeline.
00:47But in reality, what we really want in this type of animation and especially because we have a nice scrubber that we want to have control over our animation.
00:56It would be amazing if our animation would be able to be controlled from one single spot.
01:01And to do that, we want to put them all into one timeline.
01:05And that's exactly where timeline light comes into the picture.
01:09Complicated, it is not.
01:11The first step that I'm going to do to get it and work with it, I'm just going to comment down that change of FPS because I don't really want to make our animations run in one second.
01:20And I'm just going to delete all of the variables we had here because we're going to get rid of them.
01:24And instead that I'm going to create a timeline light, just a global variable that I'm going to call TTL.
01:30And the first thing I'm going to do is once my image has loaded, I'm going to go ahead here and create a new timeline light.
01:39Once I created the new timeline light, literally all I have to do to get my animation to be connected to each other is to send those animations into the add command.
01:53So I'm going to go to my timeline light and literally just send in the tweens that I'm creating.
01:58Again, timeline light, add, and I'm just going to add in our animations.
02:03And last but not least, add this last item as well.
02:11Now I'm going to just go ahead here and look for, sorry, look for every spot where we had a name to our files.
02:18So I'm going to even go ahead here and get rid of that toggle play.
02:22We're not going to even call it.
02:24I'm just going to comment this out, comment this out, comment this out.
02:27So we're not going to call any of the callbacks.
02:29We're just going to animate it through.
02:31So if I go ahead and just click on refresh, if we don't have any errors for file names that we don't have, we're going to see something interesting.
02:38That one is we had, if I just run this one more time, we'll have your animation number one going on, which was that fade in.
02:47We're not seeing the next animation.
02:49And really, the only reason we're not seeing the next animation is because we put here a very big animation time.
02:55This is 90 seconds because we got rid of our frame rate.
02:58So let me just bring it back to Earth by setting it, let's say, to one second and one second.
03:03Well, let's do one second and one second here, a delay of one second, just so we have here something to work with and click on refresh here.
03:13And one second has passed and now our animation is going to move into the next stage and the next stage.
03:18Now, notice that we have here a problem.
03:20And our first problem is that our animations are basically going through one after each other and with those delays.
03:28And in other words, if we look into our, you know, if I just look here into flash just for a second to illustrate this.
03:35So if this was our first animation and just look at the, not the animation itself, but the illustration of it.
03:42So I'm going to go here and just copy this just to create another instance of this animation.
03:46Okay, so we have your animation too.
03:48But in reality, we have your, we have really three animations.
03:51What's happening is that the first animation happens and only then the next animation begins.
03:58More over than that, if we look into our code, we're going to see that we have here a delay of a second.
04:03And because we're stacking our animations one after each other, we're also stacking the delay.
04:08So literally what, literally what we're doing is we're adding a one second delay.
04:13In our case, that would be 15 frames here.
04:15So I would have your another 15 frames delay here and that would be my second animation and so on and so on.
04:22So literally what's happening, I'm adding my first animation.
04:25Then my second one begins, but because it has a delay of one second, nothing is happening for a second.
04:30And then the next animation begins.
04:32Don't worry about the visuals.
04:33This is just, just look at the scrubbers that were created down here for illustration.
04:38So obviously one thing that I could do is just get rid of that extra delay.
04:42That already will be helpful because I'm stacking everything up.
04:45I could get rid of those use frames also because we don't want to use frames here.
04:49And I could also get rid of this delay because we know that everything is basically happening one after each other.
04:56So if I go ahead and run this now, what's going to happen is that we won't have any delays.
05:02But we're not going to have any overlap.
05:05Contrary to the animation that we had previously where we had the animation going on for a second
05:10and then the next one started in because they were in competing timelines.
05:15Now we have one massive timeline.
05:17So when I add something, it automatically is appended to the end of the animation.
05:22So literally by doing this, what happened here, if I save this, go back into my application and click on refresh.
05:29We're going to see that our animation is going to go through one, two, three.
05:32Basically doing each animation separately now without any delays between those animations.
05:38So what we're going to do in the next lesson is we're going to take a deeper look
05:41into how could we recreate that original animation that we've created using the timeline command.
05:47Because now we have one timeline and now that we have one timeline,
05:50we could go revisit that scrubber once we're done and are happy with our animation
05:54and rebuild that scrubber to work for all of our animations together.
05:58So we'll see you in the next lesson when we continue improving this animation
06:02and in the process learn the intricacies of adding elements into the timeline.
