Archive for February, 2008

20
Feb

Graphics Class clear() Method


Over the past two weeks I’ve taught two different lessons covering the basic ins and outs of the Graphics class (Drawing API). Something I noticed is that it’s not always immediately apparent when you’re starting out that the clear() method can be used to animate dynamically drawn vector graphics. That is, in both my class demos I introduced clear() by using it to erase a canvas when a button was clicked. When I described the idea of continuously clearing and redrawing graphics to create an animation there was some confusion, so I created a simple demo on the fly:

addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);

function onLoop(evt:Event):void {
	graphics.clear();
	graphics.lineStyle(1,0x000000);
	graphics.moveTo(100,100);
	graphics.lineTo(mouseX, mouseY);
}

Copy this into your timeline if you’re not sure what it does.

Continue reading ‘Graphics Class clear() Method’