ProblemYou want to draw a circle at runtime. SolutionUse the Grahics.drawCircle( ) method. DiscussionDrawing a circle with the standard drawing methods is not as simple as you might think. Because of Flash's simplified, single control point Bezier calculations, it requires at least eight segments to create a circle that looks convincingly like a circle. Making the calculations in order to draw each segment of the circle requires a fair amount of math and code. However, the Graphics class has a drawCircle( ) method that greatly simplifies drawing a circle. The drawCircle( ) method requires three parameters:
The following draws a circle with a radius of 50 and the center point at 100,100: sampleSprite.graphics.lineStyle( ); sampleSprite.graphics.drawCircle(100, 100, 50); Drawing concentric circles is simple enough; just specify the same center point for the circles: sampleSprite.graphics.lineStyle( ); sampleSprite.graphics.drawCircle(100, 100, 50); sampleSprite.graphics.drawCircle(100, 100, 100); You can fill a circle by calling beginFill( ), beginGradientFill( ), or beginBitmapFill( ) before drawCircle( ), and calling endFill( ) after drawCircle( ): sampleSprite.graphics.lineStyle( ); sampleSprite.graphics.beginFill(0xFF0000); sampleSprite.graphics.drawCircle(100, 100, 50); sampleSprite.graphics.endFill( ); |