The flash
drawing API is essentially a collection
of movie clip methods that are used to
draw objects using actionscript. In
this article we are going to examine
how to use the most basic drawing functions
in actionscript:
lineStyle()
moveTo()
CruveTo()
Creating A Simple Curved Line Using The
Drawing API
Before you call
the drawing api you must first define
the style of the line you want to draw.
To do this we use the linestyle() function.
Line style allows us to set the thickness,
color and transparency of the line we
are going to draw. If the line style is
not set nothing will be drawn on the screen.
curveTo(x,y,x,y);
As we have seen
when drawing in flash it is considered
best practice to put darwn objects inside
a movie clip "holder".
This is done.... To learn more about
creating movie clips with actionscript
see [Working With Movie Clips Knowledgebase].
The starting position for the "pen" is
at (0,200) and the end coordinate is at
(200,0). These anchor points are both an
equal distance away from the "control" point
(0,0) creating a symmetrical curve between
the two anchor points.
If the distance of the "control" point
from point is not the same as the distnce
to point b the curveTo function will create
a skewed curve in the direction of the
greatest distnace from the anchor.
In this example the control point is actuasly
off the stage. Sice the movie clip is only
300x250 the control point actually lies
200 pixels below the movie clip in virtual
space.This is OK since no point is actually
drawn but rather the number is used to
calculate the curvature of the line.
Creating Multiple Curves
Just as with straight lines we can create
multiple curved lines in flash by moving
the starting point of the pen
Curves in flash are built using a quadratic
bezier approximation that means flash uses
relatively simple quadratic equations to
create curves between two points. this
is not immediately obvious but can be clearly
seen when a simple set of four curves are
used to create a circle.
One solution is to use more than four
points but this can be time consuming
to do for each shape as the corrdinates
must be calculated for each point. The
best soultion for creating circles using
actionscript is to build a function that
creates it automatically when given a value
for radius.