Asv3's Blog

September 13, 2009

Drawing API

Filed under: flash — Tags: , , , , , — asv3 @ 7:29 pm

ActionScript allows us  to create primitive vector shapes and lines via Graphics class. Each ActionScript class that supports drawing creates an instance of Graphics class through which we care add graphical elements into it.

Say for example you have a class by name Ball.

you create a new instance of ball like

var smallBall:Ball = new Ball()

assuming that Ball is of width and height equal to 100px, to draw a border around the ball you can you code like this.

smallBall.graphics.lineStyle(1, 0x000000);
smallBall.graphics.moveTo(0, 0);
smallBall.graphics.lineTo(100, 0);
smallBall.graphics.lineTo(100, 100);
smallBall.graphics.lineTo(0, 100);
smallBall.graphics.lineTo(0, 0);

you can categorize methods of Graphics class as follows:

Drawing lines
curveTo( ), lineTo( )

Drawing shapes
beginBitmapFill( ), beginFill( ), beginGradientFill( ),  drawCircle( ), drawEllipse( ), drawRect( ), drawRoundRect( ),
drawRoundRectComplex( ), endFill( )

Defining line styles
lineGradientStyle( ), lineStyle( )
Moving the drawing pen
moveTo( )

Removing graphics
clear( )

Create a free website or blog at WordPress.com.