标签:
1 import flash.display.Shape; 2 import flash.display.GradientType; 3 import flash.geom.Matrix; 4 import flash.display.Sprite; 5 6 var myShape:Shape = new Shape(); 7 var gradientBoxMatrix:Matrix = new Matrix(); 8 gradientBoxMatrix.createGradientBox(400, 400,0, 0, 0);//Math.PI*0.5是设置渐变转动90度为垂直(默认为水平,也可设任意角度) 9 //参数填充类型,颜色数组,alpha数组,渐变比率 10 myShape.graphics.beginGradientFill(GradientType.LINEAR, [0,0,0,0], [0,1,1,0], [1,1,1,255], gradientBoxMatrix); 11 myShape.graphics.drawRect(0, 0, 400, 400); 12 myShape.graphics.endFill(); 13 addChild(myShape); 14 //然后就是把此对象设为遮罩层即可 15 var spt:Sprite=new Sprite(); 16 spt.graphics.beginFill(0xFFCCCC); 17 spt.graphics.drawRect(0, 0, 400, 400); 18 spt.graphics.endFill(); 19 addChild(spt); 20 //设为遮罩层 21 spt.mask=myShape; 22 //这时还没完成,如果这样是看不到效果的,必须得再设置这两个对象的cacheAsBitmap属性为true,才可以,即 23 myShape.cacheAsBitmap=true; 24 spt.cacheAsBitmap=true; 25 //设为遮罩层 26 spt.mask=myShape;
标签:
原文地址:http://www.cnblogs.com/frost-yen/p/4781672.html