ActionScript 3.0 Drawing API Example

This is a small module I wrote as a migration exercise from AS2 to AS3. Written using FlashDevelop and the Flex SDK, there are probably a few small things I could work at to optimize the code, but as an introductory exercise, I am fairly pleased. The actual drawing process is very smooth- I’m really impressed with the performance of the new VM. Oh, and making images available through code is very cool:

[Embed(source="bg0.jpg")]

Also of note are new drawing API methods which greatly simplify the creation of basic circles, rectangles, and such:

private var bgRect:Sprite;
bgRect = new Sprite();
bgRect.graphics.beginFill(0xCCCCCC);
bgRect.graphics.drawRoundRect(0,0,20,20,6);
bgRect.graphics.endFill();
addChild(bgRect);

The colored blocks change the drawing color, the three blocks with differently sized circle change the drawing nib, the grey box will cycle the background image, and the white box will clear the drawing:

[MEDIA MISSING]

1 thought on “ActionScript 3.0 Drawing API Example”

Leave a Comment

Your email address will not be published. Required fields are marked *