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

Drawing Lines

Learn how to draw lines using the graphics API. by the end of this video you will know all you need to know about how to create lines and set there style using actionscript.

Video Transcript

00:00All right, so we're in our actions grow three graphics API. This is our newest title. We don't need any intros
00:06Let's just get jamming start working. So let's look into our file. First of all, we just have an empty project
00:12You could ignore all the art
00:14That's just here just to remind you of what site you're in and what our topic is
00:18So our library doesn't have anything that contains anything to this project right now and we could start working
00:24So I'm gonna start off by creating a class. I'm gonna call it main same deal as we've been doing all this time
00:29So I'm creating a new class. I'm gonna click on. Ok, I'm gonna go and edit it right now
00:34It's telling me what type of flash flash or flex. I'm happy with flash
00:38It created the class for me automatically because I'm running in flash
00:41C is 5.5 and I'm gonna click on that file save as make sure that I'm saving it into the same
00:46directory as our source files in our lines because it's gonna be our first project and I'm gonna click on save as
00:56Done. Alright, so I saved the file
00:57Let me just delete a little bit of these spaces because I just hate extra space. That's not needed
01:02It's just one of those stuff. All right, and I'm gonna delete that constructor code and let's start working with our interface
01:09So first things first is let's find out what could actually create animations and there's a basic not animation
01:16Sorry, what could actually create graphics and flash what tool enables us to draw graphics and flash?
01:21There's actually a class in flash so we could actually if we want we could try to import it which is in flash display
01:27graphics
01:29Now you never really need to import it because you never really could actually create it
01:34You don't go on and come to your main class or wherever you are and say new graphics if you do that
01:40You'll actually get an error. So just for the sake of this
01:44Demo, but you're gonna do that really quickly
01:47You're really not supposed to do this if I run my application this way and I first save the file out and I run it
01:54You'll see that we're getting an error
01:56Graphics just cannot be instantiated. So you never really access the graphics on your own
02:01Now built in into almost every single type of display object
02:06You just have a graphics property that is just built in right into your class. It's true for your root
02:11It's true for every movie clip. It's true for sprites. It's true for graphics. It's actually it's true to many not all
02:17So though the test that you have to do is very simply just type this which is your object
02:21And just ask if it has that parameter graphics if you find that parameter graphics
02:27You know that it's capable of creating graphics
02:29So I want to start with a very simple example of creating lines in with the graphics tool
02:34So we're inside of that graphics package that API
02:38The first thing I want to do is I want to define the type of line that we're going to create to do that
02:43I'm going to set the style and I never really remember by heart area line style. You don't need to you
02:52Just search in the list. Okay, so line style. What is the thickness we want? That is our first parameter
02:57Let's say two our second parameter will be color. We're gonna set this color to be a really really horrible red
03:05RGB so the RGB values basically this number system if we haven't talked about that before basically splits down
03:11The red green blue into channels between zero and two hundred and fifty five
03:17The values are actually in a hex it's a mess of code
03:20which basically means that from zero hex coded basically from zero to F are
03:24The count just as much as we count from zero to nine in a regular counting the counting subsystem of hex is basically counting system
03:32Very similar only for its counts from zero all the way to F
03:36Basically after nine would be a B C D E F and that way two characters could create a come
03:42255 combinations it takes less space and it's a very common way of describing colors
03:48So the first to describe always read the next to describe
03:52G which is RGB red green blue
03:54So the second to describe green and the next to describe blue if you wanted to you could have typed numbers directly
04:00But it would be really really complicated to figure that out
04:03so we use hex values which basically starts with zero X and then those three digits for the two digits for the red two digits for
04:10Green and then two for the blue. So we're creating a green
04:14Really really red line and let's see if there's anything else. We really care about I don't think we do
04:20We don't want to change the alpha so we could leave it at one
04:23We're not worried about all the other stuff. These are stuff that obviously I encourage you to playing around with they're really not complicated
04:29it's really just about how fine-tuned is the way your line will look like and
04:35That's about what I'm gonna get into about this one
04:37There's a lot of different types of ways the line could be built and you could actually see them in motion
04:42If you just go to your line tool and you go into your properties
04:45You're gonna see all these different properties that you could do to your to your line
04:49Just look at them see how they work and you're gonna find that correlation is very very easy to figure it figure it out
04:54So we're just gonna create a line that's red
04:57Now the next step that I want to do is I want to start creating the line
05:00So I'm gonna go to that graphics library again, and I'm just gonna start lining
05:04So line two and I'm gonna say to where do I want to go?
05:08Now before we actually get this in motion. I actually forgot one thing that I wanted to talk about
05:14in our
05:15application our 0 0 coordinate by default is up here now in
05:21Mathematics, it's not true and Matthew would probably find your 0 0 down here
05:25And as you would go up the values would go up for the Y and it was as you would go to the right the
05:30Values would go up for the X and flash
05:33It's a little bit different because it makes more sense as a graphics. That is a 2d graphics application to have the values actually
05:40When 0 0 at the top and as you go down the the Y value goes up and as you go to the side your X
05:47Value goes up. So basically the Y switched and actually when you go up you're lowering your Y position and when you're going down
05:54You're making it higher. So right now we're at 0 0 what I want to do is
05:58I want to cross like a nice cross line just from the top all the way to the other side
06:03So let's make that happen
06:04So we want to line two now that we know we're at 0 0
06:07I want to actually tell it to take the stage with to go all the way to the stage within its X parameter and
06:13same way for the height itself and
06:16That's all I really had to do if I save this and run my application
06:19We're gonna get a nice X going from one side to the other side
06:23All right. Let me just
06:25Take a little sip there. All right done
06:29I took my sip and now we're ready to continue onwards
06:32All right, so I took my line and I created that graphic line not that impressive next step
06:37Maybe I want to create a full X
06:39Maybe I want to come from one side to the other side and then from this side all the way to the other side
06:44To make that happen. I want to move
06:45I don't want to create another line and to do that is that easy as well instead of line two
06:50We would create a move to and our move to we could say I want to move my move to to where I want
06:56To move it to the edge of my side width which is exactly what we were at already
07:00And I want to move my Y up to zero again
07:04I want to move it up right to this top position again, so I could draw my line back down again
07:09so let's draw the line now, so again graphics and
07:13Line two and our line two we want to go back to that zero zero original position
07:19And if you run this one more time, we're gonna see after we save it, of course
07:23Let me just save that run it one more time
07:26And we get nothing. So let's see what's going on here. Oh
07:33Right, we're ready at zeros that that okay, that's our problem. We actually wanted to do the absolute
07:39Opposite in many ways because we're in the stage with zero
07:42Which is our stage with zero and we're taking it to zero
07:45So creating a line that we can't see what we actually want to do is we want to take it to the bottom here
07:50So from stage with zero we want to take it to the opposite which would actually be
07:55Zero and then stage height
07:58so I'm gonna grab the stage height which is gonna be the exact other side and
08:03Let's see this in motion. There we go. Now. We got our nice X. Alright, so now that we got our X
08:09And let's get rid of our bunny because our bunny is starting to be in the way. So I'm gonna
08:14Hide our little bunny now
08:16Or even better. Let me just make our bunny transparent a bit. So he's not in our way
08:23So let's drop its
08:25transparency
08:27That's not so nice is it
08:30Yeah, whatever
08:32okay, so
08:34With that we just saved it down earlier to make sure that it works in the different browsers very good
08:39Alright, so now we can see our full X all is good
08:42Our next step now now that we know how to do X and Y is to move on to the next topic one thing
08:46I just wanted to say that you could change your line style obviously at any point
08:49So if I wanted to change my line style before I drew my next line
08:52And let's say I wanted my next line to be a type of yellow
08:55Then I could have created it very easily just by defining where when I want to change the color

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!