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

Advance animation manipulation

This lesson is less about learning new things and more about learning how to do things with the things we have learned. So let's get to it.

Video Transcript

00:00All right, so we're in our new round. Let's just get to it
00:03So the next step is want to add a child, but this time we want to add child in a certain index
00:09So let me just because I don't recall the name by heart. So add child by index
00:13I believe or at there you go chop the add child at and
00:17I'm gonna take our item, which is actually our TM target. We're gonna make sure it's gonna be displayed as a display object
00:27display object
00:29And I'm gonna set its index to one basically making sure it's gonna be a really really low down the totem pole
00:35So now if I run this one more time
00:37We should be able to see that our end and let me just bring this into the stage
00:39our animations are gonna go on and they're gonna kind of like snap to the bottom and obviously there's some process there there is definitely
00:46A problem in our animation right now because they're basically kind of like disappearing after they stop which is incredibly weird
00:53what we would really hope for is maybe a
00:57Contrary to our actual starting and ending position
01:00We would probably want the switch to happen not really on our repeat area
01:06But really we probably would want it somewhere inside of our on
01:11Probably somewhere in our middle line. We'd want it to switch from being higher to being lower
01:16So let's just really just for the sake of that. Let's just copy this on
01:21Repeat and we're just gonna add another one here. And let me just break a line
01:25So there's inside of it when we create our tweens instead of that. I'm gonna create here in on
01:30update and
01:32I'm gonna try to find that position on update
01:36params and I'm just gonna create another I'm gonna create that on update call back and
01:43what I want to do is I'm gonna try and figure out to pinpoint and and again, let me just
01:48Bring it bring it down to be one only so it'll be easier for us to see what's going on
01:52Really what I'm trying to find here is any value that's going to tell me how far during our time
01:58Are we in actually right now?
02:00So we saw how we could change our position with the time property, but we could actually get our current time as well
02:07So if I just make sure that I don't have here any errors
02:11What is my error here, let's see
02:14So duplicate function definition. Okay, because I forgot to actually call this function on
02:20I've got to give it a name. So on an M update. So let me just copy that
02:26And let's run it one more time
02:28So we can see that we're getting the actual seconds
02:31so would be what would be really nice if we also got here some sort of
02:36the value of actually how long is it so for that we could get the duration property and
02:43With a duration property we're gonna get how long it actually is
02:46Which would then give us a little bit more of an indication and we could divide it and make it
02:52Easier for us so we could literally get kind of like a good sense of its position in time
02:57And we could then kind of decide at one point what what point in our animation
03:02Do we want to create the switch now the the problematic part in here is is there is nothing that is a hundred percent?
03:08Accurate. So if I take this value and I can
03:11Let's call this var range
03:13time range
03:15which is going to be a number and
03:18What I'm gonna do is I'm gonna try to find a specific range where I'm gonna try and push it into that position of zero
03:24So to do that, I'm gonna just call I'm gonna try to say if time
03:30range is
03:31greater than zero
03:3419 and
03:36It's less than zero dot 20 and we're just gonna see how many times we get get that
03:44So I'm gonna just trace here in the zone for a second
03:48And let me make sure that I don't have any errors here. So time a rain time
03:53Oh, I just time range is just time range not time time range
03:57And let's run this one more time and we're gonna look into our traces
04:01So we're we could see first of all that this is really what we want because we're it's only being called once each time
04:08But our our secondary problem is this being called as it's growing and it's also being called as it's getting smaller
04:14So we really only want it to be called as it's getting smaller
04:18So I could just add here that if our counter is all basically
04:23This is not true. Right? So if our
04:27this is not true and
04:29That is completely true
04:31So first of all if we're not in the right this is means that we're in the right round
04:36And if we're in the right round and we're between 19 and 20 then we're only gonna trace in the zone
04:40So let's see this again. So
04:42Again, we got a little typo here. So let me just see what I'm what I got here wrong
04:47So it's telling it explicit correction of a type Boolean to an unrelated type number
04:52So first of all because this value is a number
04:55But that's fine. So what I'm gonna do is I'm just gonna make sure that
04:59Flash is not gonna throw the error by telling it. Hey, this is fine
05:02I know but I want to treat it as a Boolean and let's friend this one more time and
05:07We see that we have you're already an error again. So let's just follow the error
05:11So I'm gonna go all the way to the top here
05:13Term is undefined in chapter 5 in line 58 and we can see we're still having issues here in line 58
05:20So one is is it because we don't have access to our data counter. Let's just put your little trace
05:27TM
05:29data
05:30Counter now what might what might be our problem is that maybe it's being called before our data actually is
05:38Rendered for the first time or before there is any data inside
05:41But let's give it a shot and see so first of all, we can definitely see that there's an error here
05:45So let me just trace out now only the data. This is by the way, how you do debugging
05:50And first of all, if I see here I see here that we have object object
05:53I think but the first time around we're not having here anything
05:56So the first thing that I want to do is I mean I want to make sure that only if the data exists
06:01I'm just gonna add here another if our data exists as the first parameter here
06:06If data and so making sure that we first have a data object and there's no data object
06:12Then we can't really do this trick here
06:13so let me just let's just run this again and hopefully we'll get on the zone only when we want it to come through and
06:22Not more than not and not less than that. So first of all, we're not getting it. We're not getting it
06:26This is not our so let's oh look at this. I said your group greater or smaller
06:32This would never happen again. So this is or greater than 19 or and smaller than 20
06:39You see how many errors but it's fine. Yeah, and like these errors happen
06:43You just have to look at it and try to figure out what's going on
06:46so first of all, we're in the zone and our in the zone area is
06:52Happening only we're in the larger portion of the screen as you're noticing. So it's as we're going down and
07:05It's not incredibly consistent
07:07So the reason is because sometimes it's passing through it our threshold is not strong enough
07:13So we have to make a bigger let's make it a really big threshold and see if we're getting it a more than once
07:18So I made there a much bigger threshold between 0 19 to 0 22 and you can see that now we're getting it twice
07:24So I'm gonna tinker it a little bit further
07:27And until I'm saying that I'm constantly getting once and it's fine if it gets twice once in a while
07:32It's not gonna be the end of the world for us
07:33So we're in the zone and we are out
07:37Of the zone we're in the zone and it's fine if ones in a while. It's twice
07:41Obviously, we wouldn't want it always to be twice because and we're just creating an overhead
07:45Although technically speaking everything here is an over it because we're creating this if statement that's happening constantly
07:51But this is just for the sake of example. Okay, so we could see that it's being called and it's only being called when it's expanding
07:58So what I want to do next is because it's only it's called when it's being expanded
08:03Instead of adding child at what I could do is just add child which will push our element to the top of the stage
08:09and when I set my add child and I'm gonna add my display object again and
08:17Run it one more time. We're not gonna see anything right now because our only one with one item
08:21But if we're gonna run it around and we're gonna go here and add let's say a hundred items
08:27Things are gonna be popping in a lot more
08:31Which probably too much more because at the point in time where they're being popped are probably a little bit crazy
08:37But that's fine
08:38That's part of our animation experiments that we're kind of presenting and showing you and kind of diversifying our animation
08:45So that's it. That's about well
08:47what we learned is to use the on repeated on repeat params which are
08:51Really of tween max and don't exist in tween light and that really ramps really the most important new features
08:58That are added into your tween max library and in the following video
09:03We're gonna look at strict typing, but really this is the heart of everything
09:07and this is where you really take things and make it really interesting and that and
09:13Let's so let's do this next section where we're gonna move
09:16And I'm gonna definitely undo this animation because it's driving me crazy and the next video
09:20We're gonna look at hard typing. And how do you add? What does that even mean for us here in?
09:26tween max

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!