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

The onupdate callback

In the last lecture we discovered our first callback the oncomplete callback. The onupdate callback is called each time there is a new render of the animation. In this lecture, we continue and explore callbacks through looking at the onupdate in action.

Video Transcript

00:00Welcome back. So it's time for us to see another event and let me just stop this animation here
00:05And what I'm gonna do is instead of making our
00:09T-names invisible what I'm gonna do is I'm gonna place this T names right here somewhere in the stage
00:15So I'm gonna put the T names that let me set the X position of T names to be at the stage stage
00:22with
00:24divided by two and T names that Y stage stage height
00:30Divided by two. Let me just see where that's sitting
00:32And obviously this is a problem because this is exactly the center
00:36But I forgot about the width and height of my text field. So I'm gonna go ahead and add here just another
00:43And I'm gonna remove from the width itself the T names
00:47width
00:49Divided by two. Let me just see if that looks better and that looks better, but it's kind of a little bit too much to there
00:54So what I'm gonna do, I'm just gonna go right there to my text field
00:58I'm just gonna make sure that it's the copy is in the center
01:01That way if I do that, it should sit nicely exactly in the center
01:05Which is exactly what I want and we want to do the same thing for the Y T names dot height
01:12Divided by two so I should put it the text right there exactly in the center. Perfect
01:17So the next thing I want to do is I'm gonna go in my T names and I'm gonna set my text to be nothing and
01:22I'm gonna set here a new copy here somewhere
01:25I'm gonna create your private var and the copy here will be
01:30Sample text this is an example copy of a type
01:40writer a type of
01:43Tween light or tween
01:49No, no for that part helping me create some copy text
01:56animations
01:58All right, so we're gonna create a very simple text animation now one of the problems with
02:03animation in general when we're talking about these type of animations is one of the biggest problem is that
02:08For one is when I'm creating a sample text animation here
02:13The problem is is that it's not really animatable if I would take this and I would try to animate this text directly using tween
02:19Like nothing would happen. I wouldn't be able to create some sort of animation
02:22But what I really want to create is that this top copy will come in and it will come in in kind of in a delay
02:28Not kind of but it will come in in with a delay
02:31so to make this happen what I'm gonna do is what I want to do is I want to create some sort of tween and
02:37Instead of tweening directly the object that I want to animate
02:40I'm just gonna tween a random object and I'm gonna sneeze for a second
02:44So I'm gonna pause and then I'm gonna continue
02:47To continue so I'm gonna create here a new tween light and I'm gonna do a tube
02:52But instead of doing it to a visual object, I'm just gonna create here a new object
02:56Oh, you know, let me uh, I'm gonna create here a new object and I'm gonna give that object a name
03:01So I'm gonna give it a name of let's say. Oh, you know, let's because I'm gonna want a reference to it
03:07So let me just create here that object. I'm gonna call it. Oh
03:12Helper
03:13It's gonna be an object and our Oh Helper will have only one value and it's gonna be
03:20Pause for a position and in the beginning the position is gonna be zero
03:25But really where the length the position we wanted to get to is the length of the copy how much copy that we have
03:31So I'm gonna tween light
03:33to our Oh Helper and
03:36Notice it's not a visual object at all. Now. I'm gonna decide how long do I want my animation to take place?
03:41I'm gonna give it the end in time times four
03:46Because I wanted to basically
03:48type in
03:49the amount of times takes for our animation to go through from one loop to complete one loop and
03:55I'm going to put here my variables
03:58So the variable that I want to animate is pause and I want to animate it to what position I want to
04:03Animate it to animate it to sample text
04:07length
04:09Which will give me the amount of characters that are inside of that text
04:12So basically I'm moving from position zero to the amount of length
04:16That that is given to me, which is fantastic. The next thing that's left for me to do
04:21It's a call to on update method because I want to be updated every time this happens
04:26So I'm gonna call on update and I'm gonna set a function
04:30So I'm gonna be like on text update, which is I'm gonna have to create that function in a second and I on up
04:37date params
04:39What I want to do is I want to send in to the array of on update params
04:43I want to send in my Oh helper because I'm gonna need it again. Okay, so there we go. So I'm gonna close that up
04:51Close that up create that function here on text update and it's gonna accept only one parameter
05:02Which is gonna be an object
05:04And what I want to do is I'm just gonna trace out that object dot
05:08Pause because that's a property that we're animating and I want to see that that property is updating as I'm looking at the output
05:15So as a first of all, I have your little error
05:17So I'm gonna go here and try to see what is my error. I'm gonna
05:23Type mismatch count on
05:25Two expected one got zero. So let's see what is going on here
05:30So I know obviously I have a bug here an error here of something
05:34It's kind of hard to find that bug
05:36But let me just make sure that in my published settings if I go into my published settings here
05:41And to my action script three published settings
05:44I want to make sure that I am tracing out where where was that warning mode? Okay, we are in warning mode
05:50So that does not help me. So I'm gonna go into my published settings here for a second
05:57Here we go. So I wanna I wanna
05:59I
06:01Permit debugging I
06:03Want to permit debugging when I said that's true because I want to get the actual line where my code is not working
06:08And here we go. So now I'm getting the actual lines if I'll just pick any one of them
06:12I could see that my problem is happening
06:16Inside a tween light, which means it's probably happening outside of it and it's not in tween light
06:20But really because it's something that I just did recently and must be saying that's happening somewhere here. Obviously
06:26So let me just go quickly and try to see on update
06:30There's that written correctly
06:33Yes, and while I'm reading the error
06:35It's telling me that on update is expecting one but it's getting zero meaning that my on update params is not reading correctly
06:43Up-la-date, so I just saved that I just added there an extra L that shouldn't have been there
06:48And now we can see those values going from zero all the way to the length of the text
06:52Perfect. Now our only problem with this is that it's a floating value and not an integer because there is no such thing as a half
06:58A character, so I'm just gonna create here is the I'm gonna create here an index
07:03It's gonna be an integer and I'm gonna put in the I'll pose which should
07:07Automatically trunculate into an integer because of the configuration of flash the language
07:13And now we should see that the values are shifting changing and it's as an integer
07:18Perfect. So all that's left for us to do is to actually go into our actual text field to t names dot text
07:26And I'm gonna basically append to it the value of sample text, but I'm gonna slice out of it
07:34From position zero all the way to position index, which is the index of that we are currently in
07:41So if we give it a roll one more time, we should see now that our text is filling up really quickly
07:46Which for my point of view is way too quickly
07:49So I we might want to go inside of our text there and maybe put there like a 10 second
07:53Animation and have it type in slowly slowly as our animation is going on
07:58So there you go. So that's how you could create and kind of like customize create animation
08:03By the way, it's I see. Oh cuz I have your more copy than the actual
08:09You know, so let me let me to be able to see all that copy let me just go there to t names dot
08:15I'm gonna do this right here above t names that width and just to make the width a little bit bigger
08:21so if the width originally was
08:24Let's see what it was
08:26property it was
08:29266 so let me do a little low. Let me let's make it 400
08:34Okay, and we're doing that before we're positioning it that way the repositioning should work still
08:39So if we run it one more time now, we should be able to see all that copy
08:42I
08:44Believe and if not, we might add need to add another line
08:47Well, there we go. So so that's it
08:50That's basically the process of how you create an animation using tween light and tween on it for that matter
08:58for the up and not even using a visual object basically using that animation of a number and
09:04Leveraging that for whatever animation you want to create
09:06So that was a very simple and easy way to create a copy typing in type of effect
09:11Very very easily. So that's it for on update and on the update params in the next lecture
09:18We're going to start looking into different properties that come default for both tween nano and tween light

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!