| Refresh | Home EGTry.com

draw a half eclipse using clip mask


half eclipse half eclipse

ClipMask.as

package {
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Point;

	//draw half circle of Eclipse
	public class ClipMask extends Sprite
	{
		public function ClipMask()
		{
			var p1:Point=new Point(10,50);
			var w:Number=100;
			var h:Number=50;
			
			
		
			var shape:Shape=new Shape();
			addChild(shape);
			var g:Graphics=shape.graphics;
			g.lineStyle(1,0x000000);
			
			g.drawEllipse(p1.x, p1.y,w,h);
			
			var mask:Shape=createMask(p1,w,h/2);
			addChild(mask);
			shape.mask=mask;

			
		}
		
		public static function createMask(p1:Point, w:Number, h:Number):Shape {
			var sprite:Shape=new Shape();
			var g:Graphics=sprite.graphics;
			g.beginFill(0xff0000,1); //has to fill, but the color does not matter
			g.drawRect(p1.x, p1.y,w,h);
			g.endFill();
			return sprite;
		}
	}
}