Extending the ActionScript 2.0 Drawing API
In my spare time I’ve been working on a project for PolymerCode. I’ve been building a Rich Internet Application in Flash MX 2004 with ActionScript 2.0. I’ll post some more details about it when it’s closer to completion.
In the first weeks of development I’ve already encountered a number of shortcomings of the ActionScript 2.0 API. One thing that I’ve found annoying is the richness of the designer tools available, compared to the tools available via the ActionScript API. For example, to draw a dashed line with the drawing tools, you simply draw a line, and set the line type to dashed. In ActionScript there is the MovieClip.lineTo() which does not support dashed line types.
Convinced there was a better solution, I asked the all-knowing Google the way to enlightenment. Lucky for me, someone wrote a solution. Ric Ewing wrote Advanced drawing methods in Macromedia Flash MX. Unfortunately, he and his colleagues at Macromedia wrote the solutions back in 2002, in ActionScript 1.0. To use it I’ve had to update it to ActionScript 2.0. Much of the code is the same, with only a couple of tweaks.
Since Ric offered up this code for use, I think it’s only right that I do the same. I have provided the code in two flavours. One is in the form of a helper class that any AS2.0 class can call to draw a shape on any MovieClip. The second is an extension to the MovieClip class. All of the examples below use the helper class. To use the MovieClip implementation simply subclass it, and write whatever code you need. The attach it to am item in your library selecting ‘linkage’ then checking ‘Export for ActionScript’, and typing your class into the “AS 2.0 Class” text box. I’ll post an example application of this implementation soon.
I offer the following code without warranty explicit or implied. They are presented as is, and in the words of Ric Ewing,
“Some are useful, others whimsical, but all of them are free to use as you see fit. They are free of charge or obligation. I have endeavoured to make these methods robust and useful, however I can make no guarantees about their suitability to your specific needs. I similarly make no guarantees that they are bug or problem free”
Feel free to download the source code for all the examples below.
You will need the latest Macromedia Flash Player to view the demos below.
Download it now


