ActionScript图形之遮罩

ActionScript图形之遮罩

2011-03-12 21:41:53| 分类: flex | 标签:actionscript图形之遮罩 |字号 订阅

xxx.mask=yyy 这样xxx中只有与yyy交叉的部分才可见,这就是遮罩。
例子:
比较取消注释后的效果,和当前的效果
package
{
import flash.display.Shape;
import flash.display.Sprite;
public class TestMask extends Sprite
{
private var circle:Shape;
private var rec:Shape;
public function TestMask()
{
super();
circle = new Shape();
circle.graphics.beginFill(0xfff000);
circle.graphics.drawCircle(250,250,250);
circle.graphics.endFill();
rec = new Shape();
rec.graphics.beginFill(0xff0000);
rec.graphics.drawRect(0,0,500,20);
rec.graphics.endFill();
//circle.mask = rec;
this.addChild(rec);
this.addChild(circle);
}
}
}

动态遮罩
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class TestMask extends Sprite
{
private var circle:Sprite;
private var rec:Sprite;
public function TestMask()
{
super();
circle = new Sprite();
rec = new Sprite();
rec.graphics.beginFill(0xfff000);
rec.graphics.drawRect(50, 50, 200,200);
rec.graphics.endFill();

this.addChild(circle);
this.addChild(rec);
rec.addEventListener(MouseEvent.MOUSE_MOVE, createRec);
rec.addEventListener(MouseEvent.MOUSE_OUT, dropRec);
}
private function createRec(evt:MouseEvent):void
{
circle.graphics.clear();
circle.graphics.beginFill(0xff000);
circle.graphics.drawCircle(evt.localX,evt.localY,100);
circle.graphics.endFill();
rec.mask = circle;

}
private function dropRec(evt:MouseEvent):void
{
rec.mask = null;
}
}
}

百叶窗
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class TestMask2 extends Sprite
{
private var circle:Sprite;
private var rec:Sprite;
public function TestMask2()
{
super();
rec = new Sprite();
rec.graphics.beginFill(0xfff000);
rec.graphics.drawRect(50,50,500,20);
rec.graphics.drawRect(50,80,500,20);
rec.graphics.drawRect(50,110,500,20);
rec.graphics.drawRect(50,140,500,20);
rec.graphics.drawRect(50,170,500,20);
rec.graphics.endFill();
circle = new Sprite();
circle.graphics.beginFill(0xff0000);
circle.graphics.drawCircle(450/2, 110, 100);
circle.graphics.endFill();
rec.mask = circle;
this.addChild(circle);
this.addChild(rec);
}
}
}
posted @ 2012-08-18 22:14  Lunaa  阅读(123)  评论(0编辑  收藏  举报