An easy to use AS3 shape drawing class, gear, cogs, wedge, arc, star, burst

Monday, April 19th, 2010 | #FreeCodeSunday, Actionscript 3

Every other Sunday i’m going to try and release some free code. Things like projects i thought had legs, got to the prototype stage but never had time to finish, or Actionscript libraries that i think other might find useful.

In this case i’m releasing my shape drawing AS3 class. This is mainly just an Actionscript 3 implementation of the hard work done by both Kevin Williams and Ric Ewing. I’ve also used a Minimal Comps Slider as well and included the slightly amended code for that which does not require the Flex SDK (makes it easier for people not familiar with it).

Any comments, suggestions, or shapes you’d like to add just comment or send me a mail.

Enjoy, Aden.

EDIT -

Sidney de Koning has done exactly what i hoped and taken this on and made some improvements. Along with some nice speed tweaks, each method now takes in a reference to a Graphics instance instead of a Sprite class, improving the performance and making it move useful.

Nice work Sid, i’ve ammended the demo below to include his class and the associated source code. His related article…

The Flash plugin is required to view this object.



Click to download free source code

Tags: , ,

8 Comments to An easy to use AS3 shape drawing class, gear, cogs, wedge, arc, star, burst

Abraham
April 19, 2010

Hey thanks! I was about to write my own wedge class, looks like I’m going to save some time! :-P

Bertrand
April 19, 2010

Nice !
Very useful for drawing at runtime things like gears :-)

Hope you’ll go on with your #FreeCodeSunday ! ^^

Sidney de Koning
April 20, 2010

Nice one! Thanks for sharing!
I kindof re-wrote the class to take an instance of the Graphics class, so you can not only draw in Sprites but also Shapes and MovieClips. (Because Sprites and MovieClips add extra weight to your application, for movieclips it is because they have a timeline) And you are not bound to drawing one shape in one Sprite but you can also draw multiple shapes in the Graphics layer. And i did some othe optimisations. Shall i put up a link for you? Mail me if you like it.

Cheers,

Sid

Sidney de Koning
April 20, 2010

Sorry what i meant was this, was to fast with the submit button..;

Nice one! Thanks for sharing!
I kindof re-wrote the class to take an instance of the Graphics class, so you can not only draw in Sprites but everything that has makes use of the Graphics Class. It is somethimes better to draw in Shapes, because they are lighter in KB’s. And now you are not bound to drawing one shape in one Sprite instance but you can also draw multiple shapes on/in the Graphics layer. And i did some othe optimisations and throw some argument errors where needed.

Shall i put up a link for you? Mail me if you like it.

Cheers,

Sid

admin
April 20, 2010

Absolutely Sid, just mail it over and i’ll add it to the post.
I must admit it was an oversight to use Sprite as the minimum DisplayObject extendee, but this is what releasing code to the internet is all about, collaborating to get the best end result.

[...] Today I’ve been scouting the internet for a specific class, one that draws shapes. I remembered that some time ago I read an article on the Adobe Dev site by Ric Ewing about drawing shapes. But this was all done in AS2… and I hated AS2! (and so should you ! ) But I found a AS3 version. Its redone by a guy from Bristol, Aden Forshaw. [...]

Sidney de Koning
April 20, 2010

I know :) Really cool if you can add it to your post.

And once again thanks for posting this, this saved me alot of time!

This is the link: http://www.funky-monkey.nl/blog/2010/04/20/drawing-shapes-in-as3-a-class-to-draw-an-arc-star-gear-cog-wedge-and-a-burst/

Cheers,

Sid

jacob
August 17, 2010

So free as in MIT license free? Thanks!

Leave a comment

Search