
Beginning ActionScript 2.0 2006
.pdf







14
Applying Filter Effects
Filters in Flash are similar to the layer styles found in popular image editing programs. Filters allow for glow, shadow, bevel effects, and more! These effects are new in Flash 8. Previous versions of Flash allowed rudimentary effects using vector graphics libraries, which were both difficult to manage and processor intensive. With Flash 8 filters, you have the advantage of built-in pixel-level manipulation of objects as bitmaps, which means fast and easy filter manipulation of any movieClip or Bitmap object.
The filters are applied easily by declaring the filters property of a movie clip. When the movie clip changes, the filters property is checked and the filter is applied. You can apply multiple filters to the same object. You also can apply multiple versions of the same filter to the same object. This gives you unparalleled control of filter effects at runtime using ActionScript.
Filters are exceptionally easy in Flash. You can stipulate all the properties within each new filter constructor or set them individually. This enables you to reuse an existing filter rather than instantiating a new filter object. Each time you modify a filter, you must reapply it to your target movie clip using the filters property of the movie clip.
Although you can set the properties of a filter via the new constructor, it is far more readable, and easier to scan, when a property declaration list is used. This is especially helpful for group development, particularly when working with developers who might not be familiar with all of the parameters available in the new constructor.
When describing methods, the properties are listed individually rather than as parameters. If you want to use constructor parameters to construct your filter values, you can use code hints in the ActionScript panel to show you the expected order of the parameters.
This chapter examines the major filters and their properties.

Chapter 14
DropShadowF ilter
DropShadowFilter does exactly what the name implies. You’re likely familiar with drop shadows in popular image editing software. An interesting and useful detail is that a drop shadow is rendered only as a shadow of visible pixels within a movie clip or bitmap. This includes transparent PNG and GIF. A shadow will only be rendered for the visible pixels in images.
The properties of the DropShadowFilter are described in the following list. These properties can be set within the constructor of the filter or defined as properties after the construction:
alpha — Specifies the opacity of the shadow. Surprisingly, this numeric property is not a value of 0–100. Instead it is 0.0 to 1.0, so to set the alpha property of the baseline pixel of the shadow to 25, you would set it to .25.
angle — The angle, again surprisingly, is a numeric value from 0 to 360. This is unexpected because most other angle and rotation properties in Flash use radians, an alternative method for working with circular points. It is important to consider when using the Math object that some radian-to-degree conversions are required to make the angle work. As well, Flash’s stage defines 0 degrees along the x axis. That is, a value of 0 puts a shadow to the right of your movie clip. So this is a bit quirky, but after you use it a few times, you’ll get used to it.
blurX and blurY — These are numeric values (0 to 255) that describe the amount to which the shadow should be blurred. You don’t need a high value to obtain desirable results. In fact, high values can produce visible stepping. The value loosely matches the amount of pixels to which the shadow will expand, depending upon the strength property applied, and whether the inner property is true or false.
color — A hexadecimal value. If you do not specify this property, it defaults to 0x000000.
distance — A numeric pixel value. Any numeric value is acceptable, including negative values. This property determines how far away from the movie clip the shadow should be rendered. This is a two-dimensional value. Setting a larger distance only moves the shadow on the x and y plane; it does not change the size of the shadow in relation to distance.
hideObject — A Boolean. When set to true, the movie clip is hidden, but the shadow is still rendered. Unlike the _visible property of the movie clip, hideObject allows the movie clip to retain mouse interactivity. The vector points of the movie clip are still processed by the rendering engine, so this method has little to no effect on overall performance. The default is false.
inner — A Boolean that specifies where the shadow is rendered. Set to true, it causes the shadow to be overlaid onto the object and fade inward. The default value is false, which renders the shadow in the more traditional manner beneath the movie clip.
knockout — Replaces the fill areas in your movie clip with the colors that reside beneath the clip. It essentially makes your movie clip transparent while preserving the opacity of the fills. This is confusing and is best understood by simply trying it out and seeing the result. knockout enables many superb effects on existing stage content.
quality — A numeric value of 0 to 15. Use it to customize how smoothly a movie clip’s shadow is rendered. The quality setting is essentially a multi-pass setting that extrapolates more detailed pixel data for the shadow with each pass. The higher the value, the prettier your
shadow, but the more CPU intensive the shadow rendering becomes. Usually a value of 3–5 produces sufficient smoothness. (Also, the higher the value, the more passes blur previous passes, so a higher-quality shadow appears more bloomed and ambient than a lower-quality
336 shadow.)
