GlowFilter——发光滤镜
http://blog.sina.com.cn/s/blog_4bfac6ef0100y21z.html
很抱歉这个滤镜不会给你带来期待的惊喜,GlowFilter只是创建放光效果。确切的说,是在元件周围创建不同透明度的发光颜色填充(不过,这个名字实在太长了)。它的属性实际上是DropShadowFilter的子集,其构造函数如下:
GlowFilter (
color:uint = 16711680,
alpha:Number = 1,
blurX:Number = 6,
blurY:Number = 6,
strength:Number = 2,
quality:int = 1,
inner:Boolean = false,
knockout:Boolean = false
)
color:uint = 16711680,
alpha:Number = 1,
blurX:Number = 6,
blurY:Number = 6,
strength:Number = 2,
quality:int = 1,
inner:Boolean = false,
knockout:Boolean = false
)
GlowFilter的参数在介绍DropShadowFilter的参数时都已经介绍过了,所以我不再逐一解释。它与DropShadowFilter最大的不同是无法设置distance和angle。也就是说发光效果总是沿着对象的边缘(也可以解释为,发光效果是distance设为0,且无角度参数永远沿着边缘投影的投影滤镜)。
如果你需要沿着边缘绘制发光效果可以使用GlowFilter。它的主要用途主要有:为交互按钮添加鼠标滑过效果;为文字添加内发光,使其突出于背景图像;为剪影图像轮廓边缘添加发光边框的等。 GlowFilter的用途中我最喜欢的是为对象添加实色轮廓线。将blurX和blurY将至2,同时增加强度strength,然后通过quality的设定值来调节轮廓线的粗细。如图2-19.
图2-19.应用GlowFilter的矩形shape,同时文字添加了轮廓线效果
package {
import flash.filters.BitmapFilterQuality;
import flash.filters.GlowFilter;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
[SWF(width=550, height=400, backgroundColor=0xEEEEEE)]
public class GlowFilterTest extends BitmapFilterTest {
override protected function applyFilter():void {
var filter:GlowFilter = new GlowFilter(0x000000);
filter.blurX = 2;
filter.blurY = 2;
filter.strength = 255;
filter.quality = BitmapFilterQuality.MEDIUM;
filter.knockout = true;
_shape.filters = [filter];
// creates a textfield to which to apply a glow
var field:TextField = new TextField();
var textFormat:TextFormat = new TextFormat("Arial", 40);
textFormat.align = TextFormatAlign.CENTER;
field.multiline = true;
field.defaultTextFormat = textFormat;
field.text = "Glow Filter";
field.x = _shape.x - field.width/2;
field.y = _shape.y - field.height/2;
field.filters = [filter];
addChild(field);
}
}
}
import flash.filters.BitmapFilterQuality;
import flash.filters.GlowFilter;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
[SWF(width=550, height=400, backgroundColor=0xEEEEEE)]
public class GlowFilterTest extends BitmapFilterTest {
override protected function applyFilter():void {
var filter:GlowFilter = new GlowFilter(0x000000);
filter.blurX = 2;
filter.blurY = 2;
filter.strength = 255;
filter.quality = BitmapFilterQuality.MEDIUM;
filter.knockout = true;
_shape.filters = [filter];
// creates a textfield to which to apply a glow
var field:TextField = new TextField();
var textFormat:TextFormat = new TextFormat("Arial", 40);
textFormat.align = TextFormatAlign.CENTER;
field.multiline = true;
field.defaultTextFormat = textFormat;
field.text = "Glow Filter";
field.x = _shape.x - field.width/2;
field.y = _shape.y - field.height/2;
field.filters = [filter];
addChild(field);
}
}
}
这个类继承BitmapFilterTest类,同时应用到_shape对象上,另外添加了TextField对象更好的展示滤镜的效果。滤镜的模糊亮很小,而强度很大,同时设置了knockout属性剔除原有的填充色,应用到_shape和TextField对象上之后,好的展示了轮廓线的效果。