Drawing shapes using the drawing API in ActionScript 3.0 and ActionScript 2.0

by Peter deHaan on December 7, 2008

in Graphics, migration

The following example shows how you can draw shapes in ActionScript 3.0 and ActionScript 2.0 using the drawRect() method (ActionScript 3.0) and the moveTo() and lineTo() methods (ActionScript 2.0).

Full code after the jump.

// ActionScript 3.0
var movieClip:MovieClip = new MovieClip();
movieClip.graphics.beginFill(0xFF0000);
movieClip.graphics.drawRect(0, 0, 100, 80);
movieClip.graphics.endFill();
movieClip.x = 10;
movieClip.y = 10;
addChild(movieClip);

To draw the same rectangle in ActionScript 2.0, you would call the graphic functions directly on the MovieClip instance rather than the Graphic object, as seen in the following example:

// ActionScript 2.0
createEmptyMovieClip("movieClip", 0);
movieClip.beginFill(0xFF0000);
movieClip.moveTo(0, 0);
movieClip.lineTo(100, 0);
movieClip.lineTo(100, 80);
movieClip.lineTo(0, 80);
movieClip.endFill();
movieClip._x = 10;
movieClip._y = 10;

{ 1 comment… read it below or add one }

1 angel 08.23.09 at 9:40 pm

Thanks !! im still a noobie when it comes to creating stuff using pure actionscript in flash, this really helped ^^

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: