More drawing in Flash with ActionScript
In the previous article Drawing in Flash with ActionScript, I introduced you to the drawing API in Flash. We looked at how you could create simple shapes like squares, circles and ellipses using ActionScript 1.0. We created an empty movie clip to hold the shapes and used code to change the line style and fills.
The drawing API is more useful if you create functions that you can reuse throughout your Flash movies. In this tutorial, I’ll show you how to create reusable functions to draw squares, rectangles, triangles, circles and ellipses. We’ll finish by creating new movie clip methods so you can draw shapes over and over again by including an external ActionScript file.
We’ll create functions to draw a:
- Square
- Rectangle
- Diamond
- Triangle
- Circle
- Ellipse
At the end of the tutorial, we’ll convert these to methods of the MovieClip in an ActionScript file.
As with the previous article, I’ve used ActionScript 1.0 for the examples in the tutorial so you’ll need at least Flash MX to complete the exercises here. Again, I’ve assumed that you’ve got some experience in working with ActionScript and that you know how to add code to the Actions panel.
You can download the finished files from the blue Properties box that contains the article PDF. There's a heading titled Code Download and you can click the Details link next to it to get the zip file containing all of the samples.
Note: If you have difficulties downloading the source files or PDF, you might have a problem with your cookies. Delete the cookies from your machine and try again. In Internet Explorer, you can do this by choosing Tools > Internet Options... and clicking the Delete Cookies... button on the General tab.
We’ll start by writing a function to create a perfect square.
Read More