用as做濾鏡效果,每種濾鏡效果對應一個類別,這些類別將來會在Macromedia\Flash 8\語系\First Run\Classes\FP8\flash\filters 這個資料夾中找到説明檔 一、漸變斜角——GradientBevelFilter類別 二、投影——DropShadowFilter類別 三、模煳——BlurFilter類別(這個最容易了,參數少) 四、光暈——GlowFilter類別 五、漸層光暈——GradientGlowFilter類別 六、斜角——BevelFilter類別 做法是用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; }直接把Script複製到主場景的第一影格就ok了,不要忘記上面的函數哦,要注意改函數名的 一、漸變斜角——GradientBevelFilter類別 Script: 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 下面是Script中的參數和面板中的參數對比 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類別 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;下面是Script中的參數和面板中的參數對比 Distance是距離; angleInDegrees是角度0~360 blurX、blurY是模煳x、模煳y strength是強度,Script裏是0~5的數 quality是品質,只能是1、2、3,分別對應低、中、高 inner是內側陰影 knockout是挖空 hideObject是隱藏對像 三、模煳——BlurFilter類別(這個最容易了,參數少嘛) 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類別 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類別 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類別 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設定陰影顏色 |