To apply effects filters to display objects (sprites, movie clips, etc) ActionScript 3 display objects have a nice little .filters property that allows you to set an Array of effects filters at runtime. This is great for effects like Bevel, Drop Shadow, Glow, Blur, Inner Shadow, KnockOut, etc..
ex:
(assuming you've created the filter instances myBevelFilter, myGlowFilter, myDropShadowFilter)
1) Works:
_myMovieClip.filters = [myBevelFilter, myGlowFilter, myDropShadowFilter];
2) Works:
var fx:Array = new Array();
fx.push(myBevelFilter);
fx.push(myGlowFilter);
fx.push(myDropShadowFilter);
_myMovieClip.filters = fX;
3) Doesn't Work:
_myMovieClip.filters.push(myBevelFilter);
_myMovieClip.filters.push(myGlowFilter);
_myMovieClip.filters.push(myDropShadowFilter);
You're not doing anything wrong, this is just how Adobe has created the filters property. From AS3 docs:
Changing filters at run time
If a display object already has one
or more filters applied to it, you can’t change the set of filters
by adding additional filters to or removing filters from the filters property
array. Instead, to add to or change the set of filters being applied,
you must make your changes to a separate array, then assign that
array to the filters property of the display object for the filters
to be applied to the object. The simplest way to do this is to read
the filters property array into an Array variable
and make your modifications to this temporary array. You then reassign
this array back to the filters property of the
display object. In more complex cases, you might need to keep a
separate master array of filters. You make any changes to that master
filter array, and reassign the master array to the display object’s filters property
after each change.
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7db3.html
AS3 Filters:
-
Bevel filter (BevelFilter class)
-
Blur filter (BlurFilter class)
-
Drop shadow filter (DropShadowFilter class)
-
Glow filter (GlowFilter class)
-
Gradient bevel filter (GradientBevelFilter class)
-
Gradient glow filter (GradientGlowFilter class)
-
Color matrix filter (ColorMatrixFilter class)
-
Convolution filter (ConvolutionFilter class)
-
Displacement map filter (DisplacementMapFilter class)
-
Shader filter (ShaderFilter class)
Links:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7dba.html
Posted on
Friday, November 27, 2009
by Sean P
filed under