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

Gaining access to the tweens vars

Gaining access to the tweens vars can be incredibly useful when creating complex animations or when you need access to original data you used in the creation of an animation. TweenLite and TweenMax both support the vars property. In this lesson, we will explore how to gain access to those original vars from within a callback.

Video Transcript

00:00Chapter chapter 2 is just about complete. This is the last video of chapter 2 so congratulations
00:06We just want to talk about a couple of quick variables that properties that you probably want to be aware of
00:14We're not gonna do any animations with them right now
00:16I just want you to be aware of them and that is because you might need them as you're creating your own animations
00:21So what I'm gonna do is inside of that click event. I just want to in my tween to text in my text
00:26We know I'm just gonna trace out two properties
00:31One is my target
00:33Which is gonna give me the object that I'm actually animating in this case that object should be our Oh helper
00:39So for example, I might want to reset it whenever I click on that on click
00:43Maybe I want to start over
00:45Okay, and the next thing is our vars which will give me the original
00:50variables that which were sent in to the object when it was created, so I'm just gonna
00:55Create a quick for loop for var my int equals zero
01:00Well, no, no, no, no, no, what am I doing for?
01:03var
01:05Item string in
01:09Text tween
01:11Vars so we could like output and see all the different properties. So I'm gonna put your
01:16The item that's being rendered and the text tween
01:22We just paste that way easier
01:26Okay, so what I've done here is basically I'm gonna trace out the target itself that was clicked on which the target should be our
01:32Oh helper and then we're gonna loop through the property vars
01:36That belongs to that object that we've created tween light object or tween nano for that matter or tween max for that matter
01:43So I'm gonna just run this out try to capture it try to click it so we could see what are those values that are
01:48Coming back. I'm gonna get it get it
01:52Get it got it. Okay. So first of all, we could see that I'm gonna stop it
01:55And we're just gonna look at our trace
01:56We could see that our position itself is actually the current position that it's at and our on update is the function on update
02:04That we originally had so it's not giving us the original position that original item that we send to it
02:10It's actually giving us the updated object the updated position
02:13But it's literally just passing through this object that we've had earlier
02:18It's sending it us sending us that object with all the information that we had in it
02:23So for example, if we wanted to we could have reset it
02:25We could have taken that vars object reset it back to zero and maybe started the animation all over now
02:32I'm not gonna do that right now mainly only because of one reason because this does not exist in tween nano
02:38But it does in tween light. So so far everything we've talked about
02:42Existed both in tween light and on tween nano. There's one more property
02:46I'm just gonna talk about like for a millisecond and that's if you're a game developer
02:51Or you want to have direct access to every time. There's a new render every time. There's a new
02:57Something happens inside of tween light to do that. All you have to do is tween light
03:04Ticker and the ticker is a global object
03:07That is where all the event that every time something happens every time an animation is going on it will be triggered
03:13So every time every on update if there's any animation going on that ticker is gonna
03:18This is gonna output an event called ticker and then you could um, you could add an event listener and add a ticker event
03:26And then call whatever method you want, which we're not going to do on ticker
03:30So you could do something for example, if you're creating a game, this might be important to you for us
03:35It's not so it's just a side note. You could do that also with the tween nano also with the tween
03:40light
03:42Would love to hear from you a scenario where this would be very functional for you
03:45I would love to hear about it and that covers our
03:49wrapper stuff that are related to both the tween nano and the tween light and
03:54From chapter 3 we're gonna dive deeper into tween light. We're gonna cover things that are
03:59exclusively tween light
04:02starting with
04:03the difference between override
04:06Overright that was in our tween nano and our tween light
04:10So see you in chapter 3 where we will start it off talking with that override that we talked about in the end of chapter 1

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!