本文主要是介绍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);
}
}
}
这篇关于ActionScript图形之遮罩的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!