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

Randomizing and Details

Playing with the movieclip's frames by code. In this video we will look how we can interact with its frames

Video Transcript

00:01All right, so let's add that randomness and to do that. I'm just going to go to the initiation in our constructor
00:07And I'm just going to add into our MC oval
00:09We're going to approach a property of the movie clip which is called actually a method of the movie clip
00:14Which is called go to do and stop
00:18Go to I'm missing there an oh go to and stop and go to and stop expects one parameter
00:24Which is the frame number or the key frame name we're going to see what that means a label name later
00:30But right now we're working with numbers and our movie clip is
00:34Running on a timeline so every you can see our time line starts at one and every frame has enough
00:39So this would be two and three and so on and so on
00:42We want to go to our movie clip and basically asking how many frames do you have and randomly serve up a different number?
00:48So to do that we're first going to ask our MC oval how many frames it has and to do that we'll ask frame
00:55well total frames
00:58Now again as we stated before if
01:02By any chance you don't remember these properties
01:05We know that our MC oval is actually a movie clip
01:08And if we wanted to we could have set our MC oval to be a movie clip
01:13All right, and as we set it to be a movie clip
01:17We have to make sure also that flash recognizes that an LMC oval is actually a movie clip because if not when we run our
01:24application
01:26It doesn't it doesn't mind it in this scenario, right?
01:29But in some scenarios flash doesn't even know that it's a movie clip in the scenario. It knows it knows it's a movie clip
01:35So it doesn't mind us casting it as a movie clip
01:39So we don't have to worry about letting flash know that it actually really is a movie clip
01:44So the next step is now that we now that flash knows that it's a movie clip for our compiler
01:49Every time when we want to repress an MC oval and we put a dot on it
01:53We're going to get all the different properties and methods of the oval. So I'm going to click I'm going to pick go to and
02:00stop right or go to and play
02:05If we continue looking at the code that we were typing we had there
02:09We're trying to go to and stop and we're sending a property which is the total frames which we want to do that
02:14but we want to times that math random and
02:22The reason is because we want to get a value a random value between one and the total frames now
02:28we have a problem here because
02:31It could also be zero right and it's not rounded out
02:34So we want to make sure that our we're rounded out and not only rounded out
02:37We want to make sure that it always will seal upwards
02:40It would always go up and not down and to do that
02:43There is a method called seal which would basically take whatever random number that's there if it was one dot five
02:49It will push it up to two if it's one dot two it would push it up to two
02:52So it always would push the value up to the highest integer the closest high integer
02:57All right
02:59This is a great place to also see did I close all the brackets?
03:03I don't think I did but I'm going to type in the command comma and I could see okay
03:07Yeah, I'm missing one. So I'm gonna have to close it one more and we could say okay. I closed everything
03:12I don't have to worry about anything
03:14If I run my go to and stop, let's see what would happen
03:18So if I run it now we're gonna see that it's gonna hit a certain frame and then it's not going to animate
03:22Anymore, which is actually a very nice
03:25Illusion which gives a little bit more depth again
03:28But we actually do want it to animate and to do that
03:31We're just gonna change it from go to and stop to go to and play
03:35which would basically take our frame to a certain frame and then play it out and
03:39Here we go. And now our animation is very even more random now just looking at this
03:44I kind of feel like it's starting to look a little bit more like snowflakes and the animation is a little bit too linear and
03:50We're not gonna get into the details of actually changing those animations more but one thing
03:56That we could do to just give it a little bit more fun going on to it
04:00we could go into our enter frame and just
04:05just randomly
04:07move our X position
04:10So we could see that if our X if we are out of the stage we moved our X
04:15But we never really move our X if we are doing a normal animation
04:19so I'm just gonna go and add to my X 1 minus a value between Z between minus 1 and
04:261 making sure that the animation could go between or
04:30Might 1 minus between 0 and 2 making sure that animation could or turn right or left between minus 1 to 1
04:38All right
04:39So I'm gonna take 2 and I'm gonna duplicate it by math random again
04:43We and you could see how how much how many times we use math random and how useful it is
04:47And basically what we did right here is again as we said
04:50We're just creating like this jitter where the animation is going to just jump around from side to side and let's see what happens
04:56And I kind of I kind of dig this I I like it. It's kind of interesting
05:01Obviously the more time you work on it the more details you put into the more interesting. It's going to become
05:13What you really want to take out of this is that movie clips contrary to other display object types and again if we look
05:20into the chart movie clips contrary to
05:23everything else really has a timeline our
05:28Sprite doesn't our loader doesn't well when I say our stage has the stage doesn't really have a timeline
05:34But it's first child does and the way we could know that is also if we're speaking about that and we go back into our
05:40flash and
05:42If I just trace out in our constructor
05:45Let's just trace our stage and we could see our stage is a stage object
05:54But let's ask our stage does it have
05:59Frame number
06:01And we could say total does have total frames
06:04No, does it have a stop?
06:07No, so we could see that our stage doesn't really
06:10Have a timeline and the reason why it might be a little bit confusing is because the stage itself is probably more similar to a
06:16Sprite with a few more
06:18Properties, which is basically something that has no timeline
06:21And if you're asking, but how could it be that our main timeline our main FLA has a timeline?
06:27That is because our main constructor
06:30extends the movie clip and that is the route thus our main has a timeline and
06:37All this time we've been working inside of a movie clip and we had a timeline in it
06:41And now we're actually creating our own objects that have their own timelines

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!