Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Drawing curves with AS2

Drawing curves with AS2

By Jean André Mas | Published 02/24/2008 | Beginner | Rating:
Jean André Mas
Graphic designer converted since 2004 to coding. I play around with C++, OpenGL, Java, Javascript, AND Actionscript.
My website: ASWC 

View all articles by Jean André Mas
Drawing curves with AS2 part 1.

Logical following of the "Drawing shapes" tutorial, here comes the "Drawing curves" tutorial. Most likely, it will be followed by a "Drawing lines" tutorial. So let's get started and draw some curves!

1. Open your Flash software, select "new", "Flash document", click "Ok", then go to "Modify", "Document", enter 300 for the width and height and enter 30 for the frame rate.

2. Open the "Actions" panel.

3. Copy and Paste this code:

this.createEmptyMovieClip("circle_mc", 1);
with (circle_mc) {
beginFill(0xFF0000);
moveTo(100, 100);
curveTo(200,0,300,100);
curveTo(400,200,300,300);
curveTo(200,400,100,300);
curveTo(0,200,100,100);
endFill();
}


4. Hit "Ctrl+Enter" or go to "Control", "Test Movie" to test our Flash movie. You should see this:



I know it's not pretty, it doesn't look like a circle but actually to draw a nice circle we really need to know how the curveTo() method works so let's go on:

this.createEmptyMovieClip("circle_mc", 1);

We know this line already, we used practically exactly the same for the preceding tutorial, we create a new movie clip and give it a depth (1).

with (circle_mc) {

That's a new line, in fact we use the keyword "with" and assign to it the new movie clip we just created. Now everything between the next two brackets will refer to "circle_mc" which will save us some typing.

beginFill(0xFF0000);

beginFill is a method that applies a fill color, we used it in the preceding tutorial.

moveTo(100, 100);

We need to start drawing somewhere so we use the moveTo() method to go to 100 on the x coordinate and 100 on the y coordinate.

curveTo(200,0,300,100);

Here is where we start drawing a curve but unlike the lineTo() method here we need to give 4 numbers to the method to be able to draw a curve. So what are these numbers and what do they do? Well, the first and second number give a x and y coordinate for a point called control point and I'll come back to that in a few second. The third and fourth numbers give a x and y coordinate which is the end of the actual curve, let's see that in these following examples:





Flash uses the control point to draw the actual curve:



So now we can figure out what the numbers do in this code:

moveTo(100, 100);
curveTo(200,0,300,100);
curveTo(400,200,300,300);
curveTo(200,400,100,300);
curveTo(0,200,100,100);

the red numbers above tell Flash where to start and stop drawing:



moveTo(100, 100);
curveTo(200,0,300,100);
curveTo(400,200,300,300);
curveTo(200,400,100,300);
curveTo(0,200,100,100);

Now the numbers in blue tell flash where the control points to use to draw the curve are:



Still, why can't we draw a circle that look like a circle? Well, we used only 4 curveTo() and that's not enough to draw a nice shaped circle so we need more curveTo() to achieve a nice result. Let's do that in the second part...


 



Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Related Articles
Article Series
This article is part 2 of a 3 part series. Other articles in this series are shown below:
  1. Drawing shapes with AS2
  2. Drawing curves with AS2
  3. Drawing lines with AS2
Comments



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.