用as做滤镜效果,每种滤镜效果对应一个类,这些类都在Macromedia\Flash 8 Beta 2\zh_cn\First Run\Classes\FP8\flash\filters这个文件夹里
一、渐变斜角――GradientBevelFilter类
二、投影――DropShadowFilter类
三、模糊――BlurFilter类(这个最容易了,参数少)
四、发光――GlowFilter类
五、渐变发光――GradientGlowFilter类
六、斜角――BevelFilter类
我暂时就只知道这6个
做法是用new关键字新建一个相应类的对象,暂时就叫myfilters吧,然后把这个对象添加进一个数组filters_array,最后把这个数组赋值给mc的fliters属性,大功告成。
我想其中关键应该就是创建对象时如何设置里面的参数吧,我想滤镜的面板大家都很熟悉的了,那么,我就把as添加滤镜的一些参数和它们的面板相对照,这样可能更容易理解。
下面逐个举例(都是帮助里的例子啦,里面的参数名字都是可以改的,不过我觉得就用那些名字就蛮好),例子里都有函数setUpFlatRectangle(也有叫createRectangle的),是用来做一个方形mc的。
function setUpFlatRectangle(w:Number, h:Number, bgColor:Number, name:String):MovieClip {
var mc:MovieClip = this.createEmptyMovieClip(name, this.getNextHighestDepth());
mc.beginFill(bgColor);
mc.lineTo(w, 0);
mc.lineTo(w, h);
mc.lineTo(0, h);
mc.lineTo(0, 0);
return mc;
}
直接把脚本复制到主场景的第一帧就ok了,不要忘记上面的函数哦,要注意改函数名的
一、渐变斜角――GradientBevelFilter类
面板:截图暂无,就是截的滤镜面板啦,各位大哥请麻烦自己打开flash对照吧
脚本:
import flash.filters.GradientBevelFilter;
import flash.filters.BitmapFilter;
var art:MovieClip = setUpFlatRectangle(150, 150, 0xCCCCCC, "gradientBevelFilterExample");
//创建新的mc,实例名:art
var distance:Number = 5;
var angleInDegrees:Number = 225; // opposite 45 degrees
var colors:Array = [0xFFFFFF, 0xCCCCCC, 0x000000];
var alphas:Array = [1, 0, 1];
var ratios:Array = [0, 128, 255];
var blurX:Number = 8;
var blurY:Number = 8;
var strength:Number = 2;
var quality:Number = 3;
var type:String = "inner";
var knockout:Boolean = true;//设置各个参数
var filter:GradientBevelFilter = new GradientBevelFilter(distance, angleInDegrees, colors, alphas, ratios, blurX, blurY, strength, quality, type, knockout);//创建斜角滤镜对象filter
var filterArray:Array = new Array();
filterArray.push(filter); //把filter添加进数组filterArray,如果art上有多个滤镜效果,就直接添加进这个数组好了
art.filters = filterArray;//将art的filters属性设置为filterArray
下面是脚本中的参数和面板中的参数对比:
colors、alphas、ratios用来控制渐变颜色的,colors是色彩,alphas是百分比(这里面是0~1的小数),ratios是偏移量0~255(可以参考Color类)blurX、blurY是就对应面板里的模糊x、模糊y。strength是面板里的强度,是0~255的数;quality是品质,只有1、2、3分别对应低、中、高
distance是距离,默认4.0;type是类型,用字符串表示,例子中的”inner”是内侧,还有outer、fuller;knockout是个布尔值,表示是否挖空。
二、投影――DropShadowFilter类
面板:截图暂无,就是截的滤镜面板啦,各位大哥请麻烦自己打开flash对照吧
脚本:
import flash.filters.DropShadowFilter;
var art:MovieClip = createRectangle(100, 100, 0x003366, "gradientGlowFilterExample");
var distance:Number = 20;
var angleInDegrees:Number = 45;
var color:Number = 0x000000;
var alpha:Number = 0.8;
var blurX:Number = 16;
var blurY:Number = 16;
var strength:Number = 1;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var hideObject:Boolean = false;
var filter:DropShadowFilter = new DropShadowFilter(distance, angleInDegrees, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject);
var filterArray:Array = new Array();
filterArray.push(filter);
art.filters = filterArray;
下面是脚本中的参数和面板中的参数对比:
Distance是距离;
angleInDegrees是角度0~360
blurX、blurY是模糊x、模糊y
strength是强度,脚本里是0~5的数
quality是品质,只能是1、2、3,分别对应低、中、高
inner是内侧阴影
knockout是挖空
hideObject是隐藏对象
三、模糊――BlurFilter类(这个最容易了,参数少嘛)
面板:截图暂无,就是截的滤镜面板啦,各位大哥请麻烦自己打开flash对照吧
脚本:
import flash.filters.BlurFilter;
var rect:MovieClip = createRectangle(100, 100, 0x003366, "BlurFilterExample");
var blurX:Number = 30;
var blurY:Number = 30;
var quality:Number = 3;
var filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
var filterArray:Array = new Array();
filterArray.push(filter);
rect.filters = filterArray;
这个就不解释了,就三个参数,前面都介绍过了,下面遇到介绍过的参数就都不介绍了
四、发光――GlowFilter类
面板:截图暂无,就是截的滤镜面板啦,各位大哥请麻烦自己打开flash对照吧
脚本:
import flash.filters.GlowFilter;
var rect:MovieClip = createRectangle(100, 100, 0x003366, "gradientGlowFilterExample");
var color:Number = 0x33CCFF;
var alpha:Number = .8;
var blurX:Number = 35;
var blurY:Number = 35;
var strength:Number = 2;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var filter:GlowFilter = new GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
var filterArray:Array = new Array();
filterArray.push(filter);
rect.filters = filterArray;
五、渐变发光――GradientGlowFilter类
面板:截图暂无,就是截的滤镜面板啦,各位大哥请麻烦自己打开flash对照吧
脚本:
import flash.filters.GradientGlowFilter;
var art:MovieClip = createRectangle(100, 100, 0x003366, "gradientGlowFilterExample");
var distance:Number = 0;
var angleInDegrees:Number = 45;
var colors:Array = [0xFFFFFF, 0xFF0000, 0xFFFF00, 0x00CCFF];
var alphas:Array = [0, 1, 1, 1, 1];
var ratios:Array = [0, 63, 126, 255];
var blurX:Number = 50;
var blurY:Number = 50;
var strength:Number = 2.5;
var quality:Number = 3;
var type:String = "outer";
var knockout:Boolean = false;
var filter:GradientGlowFilter = new GradientGlowFilter(distance, angleInDegrees, colors, alphas, ratios, blurX, blurY, strength, quality, type, knockout);
var filterArray:Array = new Array();
filterArray.push(filter);
art.filters = filterArray;
这里的参数跟发光那个很像,需要说明的就是用来设置颜色的那几个数组里的4项依次是表示从外到内的颜色的
六、斜角――BevelFilter类
面板:截图暂无,就是截的滤镜面板啦,各位大哥请麻烦自己打开flash对照吧
脚本:
import flash.filters.BevelFilter;
var distance:Number = 5;
var angleInDegrees:Number = 45;
var highlightColor:Number = 0xFFFF00;
var highlightAlpha:Number = 1;
var shadowColor:Number = 0x0000FF;
var shadowAlpha:Number = 1;
var blurX:Number = 10;
var blurY:Number = 10;
var strength:Number = 2;
var quality:Number = 3;
var type:String = "inner";
var knockout:Boolean = false;
var filter:BevelFilter = new BevelFilter(distance, angleInDegrees, highlightColor, highlightAlpha, shadowColor, shadowAlpha, blurX, blurY, strength, quality, type, knockout);
var rect:MovieClip = createRectangle(100, 100, 0x00CC00, "bevelFilterExample");
rect.filters = new Array(filter);
参数:
highlightColor、highlightAlpha设置加亮颜色
shadowColor、shadowAlpha设置阴影颜色