In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: How can I draw a circle with dashed line/stroke?

Hi! Why don't you use the DrawArc class below?
How can I draw a circle with dashed line/stroke?
Using a for cycle and using the equation of the circle wouldn't it be too slow?
Get Adobe Flash player
by SoWhat1983 22 Dec 2009
/**
 * Copyright SoWhat1983 ( http://wonderfl.net/user/SoWhat1983 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ojWr
 */

// Hi! Why don't you use the DrawArc class below?

// forked from maesy's How can I draw a circle with dashed line/stroke?
//How can I draw a circle with dashed line/stroke?
//Using a for cycle and using the equation of the circle wouldn't it be too slow?
package {
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.LineScaleMode;
    import flash.display.CapsStyle;
    import flash.display.JointStyle;

    public class DashedCircle extends Sprite {
        private var shape:Shape;
        
        
        public function DashedCircle() {
           circle();
        }
        
        private function circle():void{
            shape = new Shape();
            shape.graphics.beginFill(0xFFcccc, 1);
            //Can i set a dashed line style?
//	    shape.graphics.lineStyle(2, 0x000000, 1, true, LineScaleMode.NONE, CapsStyle.SQUARE, JointStyle.MITER, 3);
	    shape.graphics.drawCircle(0, 0, int(stage.stageWidth / 2));
	    shape.graphics.endFill();
//            this.addChild(shape);
//            shape.x = stage.stageWidth/2;
//            shape.y = stage.stageHeight/2;
            
            
			var dashedCircle:Sprite = new Sprite();
            var arcAngle:Number            =  4;
            var dashedLineColor:uint       =  0x666666;
            var dashedLineThickness:Number =  4;
            
        	dashedCircle.addChild(shape);
			for(var i:Number=0;i<360/(arcAngle*2);i++){
        		var a:drawArc = new drawArc(0,0,stage.stageWidth / 2,i*(arcAngle*2),arcAngle,0x000000,dashedLineThickness,dashedLineColor);
        		dashedCircle.addChild(a);
        	}
        	dashedCircle.x=dashedCircle.y=stage.stageWidth/2;
        	addChild(dashedCircle);
            
        }
    }
}


import flash.display.*;
class drawArc extends Sprite
{ 
	public function drawArc(baseX:Number, baseY:Number, radius:Number, startAngle:Number, arcAngle:Number, fillColor:uint,lineThickness:Number,lineColor:uint):void {
		
		var yRadius:Number = radius;
		
		var segAngle:Number, theta:Number, angle:Number, angleMid:Number, segs:Number, ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number, return_arr:Array;
		
		segs = Math.ceil(Math.abs(arcAngle)/45);
		segAngle = arcAngle/segs;
		
		theta = -(segAngle/180)*Math.PI;
		angle = -(startAngle/180)*Math.PI;
		
		// angle += theta;
		
		ax = 0;
		ay = 0;
		angleMid = angle-(theta/2);
		bx = ax+Math.cos(angle)*radius;
		by = ay+Math.sin(angle)*yRadius;
		
		with(graphics){
			beginFill(fillColor);
			lineStyle(lineThickness,lineColor);
//			moveTo(0,0); 
//			lineTo(bx, by);
			moveTo(bx, by);
		}
		
		
		if (segs>0) {
			for (var i:int = 0; i<segs; i++) { 
				angle += theta;
				angleMid = angle-(theta/2);
				bx = ax+Math.cos(angle)*radius;
				by = ay+Math.sin(angle)*yRadius;
				cx = ax+Math.cos(angleMid)*(radius/Math.cos(theta/2));
				cy = ay+Math.sin(angleMid)*(yRadius/Math.cos(theta/2));
				graphics.curveTo(cx, cy, bx, by);
			}
		}
//		graphics.lineTo(0,0); 
	};
}