---
title: "[转] 一种完全没有边缘痕迹的渐变AS做法"
author: "AS3"
date: "2011-10-23T00:21:13Z"
tags: []
categories: ["Web前端"]
slug: "as"
draft: false
lastmod: "2011-10-23T00:21:13Z"
id: 1207940
url: "https://as3.iteye.com/blog/1207940"
---

<http://bbs.9ria.com/viewthread.php?tid=101161&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000>


```java

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;

```



![](http://dl.iteye.com/upload/attachment/574564/23c2a006-77e3-3648-8280-6138a52ce618.jpg)

![](http://dl.iteye.com/upload/attachment/574566/7b7d3d77-0b86-32ee-856d-c26becfcaa9a.jpg)









其实就是用一个渐变给这个渐变做alpha mask，flash运算之后就是这个效果（我这里是用和原来一样的渐变）

当然调整一些值还能产生一些边缘平滑的其它效果，比如这个光晕。

```java


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;


```


![](http://dl.iteye.com/upload/attachment/574568/26e73f35-7c1e-371c-a72e-98f5521f688e.jpg)