.

Page 1

This is going to be my first Actionscript tutorial on how to create graphics automatically, but its because I need to make something for a class educational studies, once again I am going to help my teach getting the newbies understand how flash works. So this is going to be a part one and I will be making a lot of actionscript tutorials where we will be using the graphic api to draw by code.

So in this Flash tutorial you will see how to draw stuff using Flash actionscript 3, it sounds scary, and I thought so too, I have been use to actionscript 2.0 for a while and found actionscript 3 quite intimidating, but this might be the first thing where actionscript 3.0 seems more simple then 2.0 so try to follow along.

This is how the final result will look like, its seems simple but look at the code at the bottom of this tutorial.


For this small tutorial you will not be needing to do anything on the timeline nor drawing anything on the flash stage, so just go to the actionscript panel and start typing (or copy/paste for the lazy ones).

The code you will need is shown just below, and this will draw you a square with rounded corners, lines with "//" are my comments telling you what every line does so you can understand the code. you can just delete them if you want.

// this first line is declaring our movieclip, (we could be making a graphic object instead by I like movieclips

// our movieclip will be declared square so when we need to set some properties we call it "square"
var square:MovieClip = new MovieClip();
// as said before we call the square movieclip we just declared, then set some properties, this is the filling, we say it should be with a blue color.
square.graphics.beginFill(0xFF);
// Now this part is a bit tricky, a couple of my friends got scared here, but its simple the values within our square here is respectively

// x position, y position, width, height, corner bending's for the last two.

//try to play around with the values and you will see the changes and understand what they represent.
square.graphics.drawRoundRect(50, 10, 300, 150, 10, 10);
// This is to tell flash that we are done with the graphic editing no need to do more here.
square.graphics.endFill();
// Last and very important thing here, if you forget this you will not see anything on the stage, because its to tell flash where to attach our square object.

// We just attach it the the main stage, we could tell flash to put in inside another movie clip like so:
SomeMovieClip.addChild.(square);
addChild(square);



No comments found ! Click here to be the first adding comments for this tutorial!