Animating the Drawing of Shapes with Actionscripting

Hello.

If I want to draw the stroke of a square just using actionscripting, I can (i.e moveto()). That will just show the stroke of a square as soon as I play the .SWF file.

Let’s say I want to animate the drawing of the stroke of a square from one point to the next. This way when I play the .SWF file, it will show the square being made. How would I go about doing so?

Thanks.

You can draw it pixel by pixel if you’d like, using lineTo. Gimme a second…

createEmptyMovieClip("square",_root.depth++);

square._x = Stage.width/2;
square._y = Stage.height/2;

square.lineStyle(1,0x000000,100);
square.markerX = 0;
square.markerY = 0;

onEnterFrame = function(){
	
	if(square.markerX < 20 && square.markerY == 0){
		square.markerX += 1;
		square.lineTo(square.markerX,square.markerY);
	}
	if(square.markerX == 20 && square.markerY < 20){
		square.markerY += 1;
		square.lineTo(square.markerX,square.markerY);
	}
	if(square.markerX <= 20 && square.markerY == 20){
		square.markerX -= 1;
		square.lineTo(square.markerX,square.markerY);
	}
	if(square.markerX == 0 && square.markerY <= 20){
		square.markerY -= 1;
		square.lineTo(square.markerX,square.markerY);
	}
}

This rounds the corners by a pixel, and continues drawing forever, but it’s a working version of what you’re trying to do.