ActionScript 遮罩层

package 
{
	import flash.display.Sprite;
	import flash.events.Event;

	public class Main extends Sprite
	{
		public function Main()
		{
			var rect:Sprite = drawRect(100,50,100,100);
			stage.addChild(rect);
			var circle:Sprite = drawCircle(250,100,50);
			stage.addChild(circle);
			circle.mask = rect;//设置圆形的遮罩层为长方形
			circle.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		private function enterFrameHandler(event:Event):void
		{
			var circle:Sprite = event.target as Sprite;
			circle.x--;
		}
		//绘制圆形
		private function drawCircle(x:Number, y:Number, r:Number):Sprite
		{
			var circle:Sprite=new Sprite();
			circle.graphics.beginFill(0);
			circle.graphics.drawCircle(x,y,r);
			circle.graphics.endFill();
			return circle;
		}
		//绘制长方形
		private function drawRect(x:Number, y:Number,w:Number, h:Number):Sprite
		{
			var rect:Sprite=new Sprite();
			rect.graphics.beginFill(0);
			rect.graphics.drawRect(x,y,w,h);
			rect.graphics.endFill();
			return rect;
		}

	}

}

你可能感兴趣的:(actionscript,遮罩层)