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

Shapes

What are shapes? Lets see what they are and how to work with them. In this video we will meet for the first time drawing dynamically elements to the stage.

Video Transcript

00:01Back to our famous chart, and we've been working with movie clips and
00:05Really what there was besides it having a timeline that was only real reason why we needed to use a movie clip
00:13What I want to do is revisit our code and get rid of the timeline and see how could we create it?
00:18One is we you know like we want to be efficient right the more
00:23Just logically the deeper our types of
00:26Objects are the more complex it gets the harder it is to process because there's more things going on
00:32So if we would work with a sprite instead of a movie clip that would be much more efficient if we would work with a display
00:37Object container, they'll be much more efficient
00:39If it would work with an interactive object that would be much more efficient only problem
00:45is is that well not a problem is we don't even need our item to be an interactive object and
00:52That's where our shape comes into place because all we're really using is a circle
00:57So if we're going under the assumption that we're not going to use the timeline and there's no interactivity involved with our animation
01:03We could go ahead and work with a shape
01:05So let's see how could we create a shape on the fly without using any any library assets so to do that first of all
01:13I want to just get rid of all of the timeline things which was our movie clip elements
01:18And I also want to get rid of the
01:21Where did we do that gonna get rid of the jitter? No, we could keep the jitter
01:25There's nothing wrong with the jitter, so that's all we had to do we got rid of
01:29We got rid of our movie clip related information
01:32The next step would be is now I'm just gonna keep the name as MC oval
01:36Just because we already have the name and we don't want to run through everything and rename everything
01:40or maybe if we want we could actually run through everything using our
01:46Help our our find find and replace
01:50Which would be the command F?
01:52But I don't really feel like changing the name. Let's just stick to the name that we have
01:58First of all we don't use movie clips anymore. We're gonna use a shape
02:02Now we want to make sure that we're actually importing our shape, so let's make sure that we import it flash
02:14display
02:15shape
02:18All right, if we wanted to we could have let it import automatically
02:21But we want to make sure that our movie clip is still there
02:23We're importing our shape and now we're treating this element as a shape so because it's a shape
02:28We're not going to instantiate a new LMC
02:31LMC
02:33Oval, but we want to instantiate a new shape
02:36So instead of instantiating a new LMC oval I can instantiate a new shape
02:44Open closed bracket, and I have my shape now obviously if I run my application right now
02:48I'm not gonna see anything even though everything is working just as it did before
02:52Because our shape right now is empty it has nothing in it and to add something in it
02:57It doesn't have children, but we could draw directly onto our shape and draw a shape onto it
03:02So I'm gonna go into my MC oval, and I'm gonna look for our graphics property
03:08Which is an object you could see it's a type of shape as well. Well it belongs to the shape
03:12It's a graphic display type and if I just type that one more time
03:17I could begin fill if I want to
03:20And I that's exactly what I want to do
03:22I want to begin fill and I want to select a color, so let's say we're going to select a color of
03:28red
03:30RGB red green blue so we're going to do full on red and
03:35We're going to keep our alpha at 100%
03:37Alright, so we're already in good shape as we begin to fill something we always want to end the fill as well
03:43So I'm going to call my MC oval
03:46graphics and fill and
03:49That way I ended my fill as well, but I haven't did I haven't done anything anything all I told to flash is that our fill color
03:55Is going to be red?
03:58So let's draw something so I'm going to go to my MC oval again in between my begin and end and again
04:05I'm going to approach my graphics and
04:07In my graphics. I'm going to select one of the one of the methods that enable me to draw things and we're going to see that
04:14There's a draw circle draw ellipse draw graph draw path and so on and so on and I do encourage you to play around with it
04:21But right now we're just going to draw a little circle, and we're going to position it at zero zero
04:27For the x and y and the radius. Let's just give it a random radius. Let's say
04:32We're going to give it a radius of 12
04:36Very good
04:37So now we created a new circle with a radius of 12 and all the rest is really the same nothing needs to change
04:43And if we run our application we should see that our elements are running on the stage and they're
04:51Hopping along and doing more or less what we want them to do
04:55and we could see that we have some sort of small issue on the bottom here and
04:59That's probably because we probably should just adjust our enter frame logic

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!