02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Integrating pause points

All our controls so far have been external to the timeline. In this lesson, we will introduce the TimelineLite.addPause() method and see its usage.

Video Transcript

00:00In the last lecture we saw how to add a pause play functionality that wasn't connected
00:05to the actual timeline itself because we just said hey stop, alright continue.
00:10The next step right now is we want to actually tell the timeline when you reach a certain
00:13point in the timeline we want to have a pause there and that's exactly the topic of this
00:18lesson.
00:19Alright, that's it, let's leave it.
00:23Pause I'm going to pause this and move to the video and pause play and that was
00:27really lovely but what we really want to do is add a pause to our event so we're going
00:32to go ahead and create that logic.
00:35So we're going to go ahead and really what I want to do is basically create an animation
00:38and at any point in time basically say hey I want to pause our playhead whenever we reach
00:42this point.
00:43So if I go ahead and add that button so we're going to go ahead there and just create
00:49that controller.
00:51Don't worry it's going to be very easy.
00:53Add pause and I'm going to call the add pause function and I'm going to call the control
00:59bar so make sure that it's going to go into the control bar, copy the function and create
01:04it really quickly.
01:05I'll go all the way to the bottom right after our kill and I'll create the function really
01:09quickly.
01:10Now the function itself is really cool, it's very simple, it's called add pause.
01:15Now if you just call the add pause on its own it's not going to do really anything
01:19because it's going to add the pause in the end of our playhead which is not something
01:24that you're going to have that is very visible.
01:27So if I go ahead here and just save this, go back to my application, click on refresh,
01:31it will work if I knew that in advance and I come here and I move something and I add
01:36another something, move another something, I add a pause state, move, move, move and
01:41I go ahead and I replay inside of our, where's our replay, there we go, replay.
01:48It's going to pause in the pause state that we created and it's not going to just trigger
01:52automatically, I'm going to have to click on to switch our pause state, all right?
01:58So it's literally every time we click on pause it will pause it but the only problem
02:01is that if I try and I click now on replay and I pause the replay and I say okay I want
02:07to have a pause state right here and I click on replay again it's not going to add a
02:10pause state there and the reason is because it's always adding it by default to the end
02:15of our timeline.
02:18So for me to solve that problem, what I could do is go to my timeline and ask it what time
02:22is it in right now and send that as the first parameter, making sure that if we're in the
02:28end it's going to get the end, if it's in the middle it's going to get the middle and
02:31now our pause state will automatically not be only based on if it's in the end or not
02:37but it's going to be based on the current position that we're at.
02:39So if I add here another item one, two, three and I go ahead and I click on replay
02:46and immediately pause it when there's only one item and I click on add pause
02:50and I replay from the beginning we'll see that it's going to pause at that state
02:54and then I could replay it if I want to. Alright so that's about adding pauses
02:59and I want to talk about another something so let's talk about when we add
03:02a label we'll automatically pause every time we add a label. So to do that I'm
03:07going to go ahead into my creation of labels right here let's find our
03:13creation of labels on label change and in on our label change I could go ahead to
03:19my timeline and say pause add pause where do I want the pause to take place in the
03:24current label. So it doesn't even matter if we're in that where are we are in our
03:29time head I'm literally giving it our label itself adding a pause state
03:33inside of that label. Now in my case what I really want to do is every time
03:38that there is a pause state here when we reach a new label what I want to do
03:42is I really want to call a callback that will update the copy inside of our
03:46labeling text and say the name of the label that we're in. So to do that what I
03:52want to do is I'm going to call I'm going to add a callback and I'm going to
03:55call this on label update and I'm going to give it parameters I'm going to
04:01only give it one parameter which will be the label itself and if I want to I
04:06could give it two parameters which is basically the this wrapped so how about
04:11we do that we give it the this as the first parameter or even better how about
04:15we use the fourth parameter which is changing the scope alright so first was
04:20the actual label itself that we're pausing or the time in the timeline
04:24that we're pausing the next is the callback that we want to add wasn't
04:28mandatory and next is the array of elements that you want to send into that
04:32function and last but not least is the scope of the function. So if I go ahead
04:36here and just create a new function and I'll just paste inside the name of
04:40that on label update that we've created I could refer back to the object to that
04:45jQuery object with this because the jQuery object is going to be sent
04:49through and literally I could just go to my text here and just make sure that
04:53I'm updating my text to be the label that we're sending in as our parameter
04:57so I'm going to go right here LBL save this whole ordeal and if we don't have
05:03any bugs it should be working really really well so if I click here and
05:06refresh I'm going to just call the start which is going to create a pause
05:11state and I'm going to go ahead and I'm going to start adding things and I'm
05:15going to just add an item and I'm going to go ahead and add another item and I'm
05:21going to go ahead and add another item and now let's let's just add a nice
05:25amount of items so I'm going to just add here six items in total so this is
05:30going to be our triangle state so I'm just going to go ahead here and call
05:34this triangle or try, right? So we have a triangle state, but how about we create
05:39now a squared state or a more closer to a square state, a rectangular state, and
05:47we'll call this rec. Now if I go ahead and replay from the beginning, notice
05:56what should happen with our copy right here. So when I click on replay, it
06:00should start over and we're gonna see the mark start. Because there's a pause
06:04state already in the beginning here, it's not really playing. So I'm gonna have to
06:07go ahead and say I want to play from start and it's gonna start playing from
06:13the start spot, stopping when it reaches the triangle area. And when we reach the
06:22triangle, I could go ahead and resume it or I could say play triangle and now the
06:26triangle area will play until it reaches the rectangle area, which was our last
06:30label, but also the last frame. So I could go ahead if I want to and just
06:34add a little bit of more motion here. So this is what will happen afterwards. And
06:39if I go play rec again, it's gonna go to that rectangle area and let's play it,
06:44right? Because when we jump to that spot, it always pauses it, but so jumping it
06:48will pause it. But if I click on it again because we're already in there, then
06:51it'll start playing it. And that's because there is a pause state that is
06:54sitting inside there. So that's basically how you add labels and really control
06:58labels. We're not done talking about labels, but in the next lecture we're
07:02going to move into timeline max because we want to take advantage even further
07:06of the label logic. And it's time for us to see what timeline max has to offer to
07:12us because we're nearing the end of our course.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!