在http://www.riacn.com 首页看到一个这样的东西,作者用的是修改MovieClip原型的方法, 这种方法不是很好. 破坏了封装性.用AS2修改了一下.
// AS2 Soft Edge Class // origin AS1 author : V1.0 by Mario Klingemann // see
class SoftEdgeClass extends MovieClip { static var symbolName:String = "__Packages.SoftEdgeClass"; static var symbolOwner:Function = SoftEdgeClass; static var symbolLinked = Object.registerClass(symbolName, symbolOwner);
public var work_mc:MovieClip; public var color:Number = 0; public var blur:Number = 0;
static function soft(base_mc:MovieClip, name:String, depth:Number,o:Object) { var mc = base_mc.attachMovie(symbolName, name, depth,{blur:o.blur,color:o.color,work_mc:base_mc}); // return mc; }
function SoftEdgeClass() { softEdge(); }
function softEdge() { var b = work_mc.getBounds(work_mc); for (var i = 0; i <= blur; i++) { lineStyle(3, color, 100 - (100 / blur) * i); roundRect(b.xMin + i, b.yMin + i, b.xMax - i, b.yMax - i, blur - (i * 2 / 3)); } lineStyle(3, color, 100); beginFill(color, 100); drawRect2(b.xMin - 1, b.yMin - 1, b.xMax + 1, b.yMax + 1); roundRect(b.xMin, b.yMin, b.xMax, b.yMax, blur); endFill(); }
function drawRect2(x1, y1, x2, y2) { moveTo(x1, y1); lineTo(x2, y1); lineTo(x2, y2); lineTo(x1, y2); lineTo(x1, y1); }
function roundRect(x1, y1, x2, y2, r) { r = Math.min(Math.abs(r), Math.min(Math.abs(x1 - x2), Math.abs(y1 - y2)) / 2); var f = 0.707106781186548 * r; var a = 0.588186525863094 * r; var b = 0.00579432557070009 * r; var ux = Math.min(x1, x2); var uy = Math.min(y1, y2); var lx = Math.max(x1, x2); var ly = Math.max(y1, y2); moveTo(ux + r, uy); var cx = lx - r; var cy = uy + r; lineTo(cx, uy); curveTo(lx - a, uy + b, cx + f, cy - f); curveTo(lx - b, uy + a, lx, uy + r); cy = ly - r; lineTo(lx, cy); curveTo(lx - b, ly - a, cx + f, cy + f); curveTo(lx - a, ly - b, lx - r, ly); cx = ux + r; lineTo(cx, ly); curveTo(ux + a, ly - b, cx - f, cy + f); curveTo(ux - b, ly - a, ux, ly - r); cy = uy + r; lineTo(ux, cy); curveTo(ux + b, uy + a, cx - f, cy - f); curveTo(ux + a, uy + b, ux + r, uy); } }
|
关键词: |