Yes, I'm calling you
Trigger function calls at specific points in the timeline. In this lesson, we will use the TimelineLite.call method.
Video Transcript
00:00As you probably discovered by now there are many ways to interact with the timeline from the add
00:05function add method the to the from the from to we've seen o2 how to actually create a
00:12property setting it a property with the set value and now we're ready to move into the next item
00:17which is the call that enables us to call a specific function whenever we want to let's
00:22see what we mean by that it's it's one of my favorite features because it's not only animations
00:27you could also trigger specific functions at specific points right directly inside of your
00:31timeline very excited you can very convert viable right now because it doesn't really matter to us
00:37but we'll just try to find some usage that so we could see that value and what i really want to
00:42have is some sort of a callback in between our animations and to do that it's really not that
00:48hard we're going to use a method that's called call to do that so let's jump ahead and see what
00:53it is but literally what i want to do is i want to take that zero to geek and actually start it
00:57from 10 geek and have it nine eight seven six until we reach two because we have eight images
01:02in total so let's get started and the first step that i want to do is i want to basically
01:06make sure that i'm calling that call method right in our right after we trigger an animation
01:15now because the default behaviors of timeline light is it always adds an item in the end of the
01:21index where that last animation completes that's the default if i go ahead and i do a call
01:27i'm going to call it in the end of that animation so if i go ahead here and i just add a call i could
01:31literally just add your function that i want to call in this case i want to call a function called
01:36update copy the second parameter that i want to send is basically uh whatever value i want is the
01:41parameters of that function in this case i want to send this index and notice how i'm taking
01:46that index from the you know you should know this already because we're in the advanced course
01:49but it can't hurt to remind that our index is a primitive value so we could by copying it
01:56right here it doesn't matter that this function is being called over and over and over because
01:59the value itself is being pasted into you're not the variable itself that way when we run our
02:05application with these two parameters if i just create this function really quickly and i call
02:09it update copy and it has a parameter of index and i go ahead and just call it out to see what's
02:15inside of that index we should be able we should see the value of our of our element
02:23starting from one going all the way until it reaches that um eight now really what we want
02:29to happen is we want to start not from one but from let's say we want to start from 10 probably
02:35now we don't want to put a hard-coded value because it's always a bad idea to put hard-coded
02:39values but i could literally just go ahead and ask for that last value to know what the last
02:44value is and just go ahead here and just ask for that geek ii dot last minus whatever the index
02:51is and i probably want to also add to this the value too because i want to always start
02:58from at least two so like that we're starting from 10 and if we give it a test here let's see what's
03:03going to happen we'll see our first value is 9 8 7 6 5 4 3 2 and that's that is where we
03:11want to reach so let's find that it's at 9 because we want to reach 2 so that's good because
03:14we don't have another animation so that's good so we have it going from 9 all the way to 2 which
03:20is exactly where we want it to go next stage is to actually update our copy in our h1 to basically
03:27update each round so that's going to be the easy part i could literally just go up here and just
03:31save the initial copy that way we have access to it all the time so i could type here maybe h1
03:36value and i could just go ahead and approach that h1 and ask for the value of it so i'm
03:43going to go that text ask for the text beyond that i could also chop out the first two
03:48parameters so i could call the slice right in it and say i want to start from position 2
03:54by doing that if i do your quick console again i'm literally starting from position 2 which is the
04:01you know after 0 and 2 so that was 0 that was 1 and the letter g is our the letter g is our second
04:10parameter so this is 0 1 2 and geek is that beginning so if i saved it i believe i did save
04:16it we'll see that now we see geek learning better is better perfect so we're very very close all
04:21that's left for us to do is go ahead and update this text making sure that we each time put inside
04:26of it also a leading zero if the value is lower than 10 in our case the value is always lower
04:32than 10 so i could literally just go ahead and just put your zero plus whatever this value is
04:41and plus also our actual copy that we stored in our geek 2 and that was called h1 value so if i go
04:52ahead here and just save this let's see if everything's working so we should expect to see
04:56here when the animation first animation ends and the the values go down and go down now
05:04the problem that we're having here is it's actually reaching zero for some reason so let's
05:09go ahead and troubleshoot this and the way oh what's basically happening is that we have this
05:15addition going on here but what we really want to do is we want to put this in a bracket
05:20because this plus two scenario we don't really want and we don't we don't need so many brackets
05:25we could just make sure that that plus two is inside the bracket because this is the numeric
05:30areas and we don't want by any chance to have these values attached to the string so we want
05:35to make sure that it first turns into that value that we want it to be before we connect it to
05:40that number so if we go ahead and click it refresh we'll have your nine eight seven six five four
05:46three two all that's really left for me to do is to to basically have that initial start
05:52at 10 instead of at nine so i could just go ahead here after i set that value there i could
05:57literally just go ahead here and just go ahead to that h1 again and just set that value to be 10
06:05instead of or even easier you know just thought about it i could literally just call update copy
06:11and just go ahead here and just call update copy and just send the value 10 into it that way
06:18we'll have that value but if i do that then i have to take into consideration that trailing
06:22zero that we've put so another option is just to do it ourselves because we don't have to add
06:27complexity into a function that gets called so many times so literally i could just go ahead here
06:34and just add hard code the value 10 that's fine just hard code the value 10 in this scenario
06:41that way we're starting with 10 and just by doing that where animation should be starting from 10
06:47nine eight seven six five four three two bam learning better is better now before we wrap up
06:53this title this lesson i want to go right back into that call method because there's a few
06:59more things that this call method could do one of them is this third parameter and that third
07:05parameter is scope you've met scope before many times so i could literally say i want you to be
07:10a specific scope for example i could say i want you to be the h1 just as an example or i want you
07:18to be that geek geek 2 by setting it to be that geek 2 then i might be able to avoid the need
07:24to use hard-coded values such as geek 2 right here so if i wanted to i could have set it to
07:28geek 2 go ahead right in here set it to geek 2 and now all places that i set geek 2 i could
07:35literally just approach it as this instead and then i would have i wouldn't have to approach it
07:40in another way and if i wanted i could have stored also that h1 in our geek 2 and all all this type
07:46of stuff just makes it easier for us to create motions and animations and things that don't have
07:52too many hard-coded values inside of them um so that that's one and if i go ahead and click on
07:57refresh here and say see we should see that everything should continue working just as it
08:02did before the last but not least before we wrap this up we'll notice that we have a slight
08:06problem not a big problem is although the animation completes really at those stages where
08:11we have it but wouldn't it be lovely if we could have it run like half a second or 0.2 seconds
08:18before earlier and we sure can and that's what we do with the fourth parameter of the call function
08:25which is the position which we've seen the position quite a lot of times already so i'll
08:29just go ahead here and just set the value to be basically plus equals of the value i want or
08:35minus in my case i want it to be a little before the animations are over each time so i'm basically
08:40positioning it in an offset of our timeline if i say this we're not going to see a dramatic
08:47difference between the two but we should see the reaction of that 6 5 4 more correlate to that
08:53new comp content that's coming in each time that for me feels a little bit more more natural
08:58although this animation isn't incredibly natural as it is so that's it that was the call method
09:04and we've seen it in action and that's it we're in the next lesson we're going to continue exploring
09:09more timeline light thingies
