当前位置: 代码迷 >> Web前端 >> [转] 一种完全没边缘痕迹的渐变AS做法
  详细解决方案

[转] 一种完全没边缘痕迹的渐变AS做法

热度:121   发布时间:2012-08-22 09:50:35.0
[转] 一种完全没有边缘痕迹的渐变AS做法
http://bbs.9ria.com/viewthread.php?tid=101161&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000

import flash.display.Sprite;
import flash.display.Shape;
import flash.display.GradientType;
import flash.geom.Matrix;

var sp:Sprite = new Sprite();
var sh:Shape = new Shape();
var w:Number = 255*2;
var mat:Matrix = new Matrix();
mat.createGradientBox(w,w,0,-w/2,-w/2);
sh.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[0,255],mat);
sh.graphics.drawCircle(0,0,w/2);
var sh2:Shape = new Shape();
sh2.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[0,255],mat);
sh2.graphics.drawCircle(0,0,w/2);
sp.addChild(sh2);
sp.addChild(sh);
sh.cacheAsBitmap = true;
sh2.cacheAsBitmap = true;
sh.mask = sh2;
this.addChild(sp);
sp.x = 300;
sp.y = 200;















其实就是用一个渐变给这个渐变做alpha mask,flash运算之后就是这个效果(我这里是用和原来一样的渐变)

当然调整一些值还能产生一些边缘平滑的其它效果,比如这个光晕。

import flash.display.Sprite;
import flash.display.Shape;
import flash.display.GradientType;
import flash.geom.Matrix;

var sp:Sprite = new Sprite();
var sh:Shape = new Shape();
var w:Number = 255*2;
var mat:Matrix = new Matrix();
mat.createGradientBox(w,w,0,-w/2,-w/2);
sh.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[0,255],mat);
sh.graphics.drawCircle(0,0,w/2);
var sh2:Shape = new Shape();
sh2.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[70,255],mat);
sh2.graphics.drawCircle(0,0,w/2);
sp.addChild(sh2);
sp.addChild(sh);
sh.cacheAsBitmap = true;
sh2.cacheAsBitmap = true;
sh.mask = sh2;
this.addChild(sp);
sp.x = 300;
sp.y = 200;




  相关解决方案