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

Moving into TimelineMax

Throughout all the chapters of this course, we were focused on the foundations of this library as we dug deep into timelines and how they work. We explored most of the methods in TimelineLite and now we are ready to step into TimelineMax. In this lesson, we will meet our first TimelineMax method that will return the current label we are in (currentLabel).

Video Transcript

00:00Alrighty, we're ready to move into TimelineMax, and we're going to stay in TimelineMax for the
00:05rest of this chapter, and the scores for that matter, and what I want to talk next is go
00:09back to labels and start looking at a lot of different functions that help us have
00:14a lot more control over labels that are added into TimelineMax, starting with what is the
00:19current label that we're in at all.
00:21It wouldn't be nice if we could actually let the user know at what section and what
00:24label are they in, and that's exactly what we're going to be doing next.
00:29I am incredibly excited because we're getting really close to the end of this
00:34course, but before we finish it, it's time for us to jump into the world of TimelineMax.
00:40We're going to learn a lot of new things in it, really fun things. Most of the things
00:44you'll find in TimelineMax are going to be very similar to the things you'll see
00:47between the difference between Light and between Max, and we'll see that a lot of
00:53stuff such as yo-yoing and repeating and all these type of built-in functions
00:58that are incredibly similar to the functionalities, extras that are available
01:02in a tween light and tween max are going to be also available inside of our
01:06TimelineMax. I'm not going to go over most of them because most of them are going to
01:10be incredibly intuitive if you've been working with the animation library for a
01:14while, and if you've been following our three titles in JavaScript, G-SAP
01:19animations, and you've definitely been playing around with it for a while.
01:23So let's jump back into Labels, but now we're going to change our TimelineLight
01:29to be a TimelineMax, which will open up the door to more things that we could do
01:34with Labels, which is quite exciting. So I'm going to go ahead here and instead
01:39of creating a TimelineLight, I'm just going to go ahead and switch it to be a
01:42TimelineMax. Now that it's a TimelineMax, what I'm going to do next is I want to
01:48have here a callback on update, and on update, I want to have an on update check,
01:55and we're going to see what we're going to do in here. What we're going to do is
01:59basically what I want to do is I want to, let me see where I'm going to put
02:03this, let me put it just right here, function, and what I want to do is I
02:10want to basically see what is my current label, and I want it to be
02:14traced out every time there's an update. So to do that, I'm just going to
02:18go into my console.log, and I'm literally going to ask for my current
02:23Timeline, which is a TimelineMax now, and I'm going to ask for the current label.
02:29Now if I go ahead and save this, and I play ahead, or play ahead, so first of all,
02:33if I just refresh here, and I'm just going to create an item, add and move it
02:38around, I'll call this move one, and I'll move it again, and this will be
02:46something else. Alright, so we have here two different areas in our
02:52Timeline. So if I go ahead now and I replay, notice what's going to happen
02:57inside of my Timeline as it's moving. So I'm going to click on replay, so
03:02we'll see in the beginning it's null because there was nothing there, because
03:05we never set a Timeline there, and then we move to move one, and once we got to
03:10move one, it froze. And if I replay again, and it's going to be a null, and then
03:16move two. Well, replay is not really helping us. What I want to do is
03:21actually click on pause to force it to move, and now we're at something else, and
03:25if we play... So you see what's happening here. Basically every single update, it's
03:30checking to see what is the current label. So what I want to do next is I
03:36want to basically go into my code here, and I'll just add here some
03:40basic logic here, and what I really want to do is I want to go to this copy here
03:44of our label copy. So I'm going to go ahead and just select the label copy,
03:49which is not going to be this this time around unfortunately, but I'm going to go
03:53into my label itself, and what I want to do is I'm going to approach the
03:57label itself that has the ID of label, and I'm going to just set the copy of
04:02the current label in it, but only if it's not null. So if the copy is null,
04:07then I want to put here no label, and if not, I want to actually put that current
04:13label. Now just to cut down the amount of times I'm calling the function, I'm just
04:17going to call here basically a new variable, which I am going to... Oh, you know,
04:21let me show you something actually really interesting. So right, I was doing
04:24here a ternary operator where I have there the condition. If the value was
04:29false or null would be the same, then it would put this, and if not, we would
04:32put the other one, which we've seen that before, but instead of that, what we
04:35could do is this, basically put here an or command, and what that would do is
04:40basically see if this would come back with any value, this would never happen.
04:44But if this would come back with a value that is negative, such as false or null
04:48or undefined, or even zero, then this area will trigger, and when I do a command
04:54like this, it's actually going to send it through, and it'll send it to my object
04:57or this or that. So if I go ahead and save this, and I'll just get rid of
05:01that console, because we don't need that console anymore, and I want to do
05:05another something, and I don't want to have a pause state anymore whenever I put
05:09a label. So to avoid having a pause state, let me find where that I actually put
05:14the label inside, and I'm just going to comment out the pause, because I don't
05:19want to have an automatic pause, because I want us to be able to see as things
05:22are changing. Now one thing is, is because the label is in a very specific
05:26spot, we're not going to see the whole thing, right? So you know, let's
05:30leave the pause for a minute, and then we'll take it off once we move on to the
05:33next exercise, but that is the plan. The plan is to get rid of that pause state,
05:38and I'm going to go ahead into my browser here, and in my browser I'm just
05:42going to click on refresh, and we're going to give this another try. I'm going
05:45to add an item. Let's this time around add two items, and I'll call this two,
05:49and then I'll move them, and let's call this moved, and if I go ahead and I
05:57click on replay, first of all there is no label, then we moved into label two, and
06:02if I click on pause to make it play, we'll see that from two we're
06:08going to move to moved. So only in our first first first frame, we didn't have
06:12any copy there, but thereafter we do, and if I just click on replay from the
06:18beginning, there was no label, and then we moved on to two. Alright, so that's
06:22the current label, and the current label always gives me the label that is
06:26currently active, which basically also means it's the label that is active,
06:30which is if there was a label earlier before that that was defined. If there was
06:35a label that was defined earlier, that's the label that we're in. We're basically
06:39the last name that was set is the label that we're in. Alright, in the
06:43next lesson, we're going to continue with this logic, and this is a timeline
06:47max logic, and I want to add here two controllers. One will be prev, or last
06:53label, and one will be next label to enable us to go backwards and to be able
06:58to go forwards, or even we'll call it before and after, and we'll see you in
07:03the next lecture when we add those controls.

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!