DropShadowFilter (flash.filters.DropShadowFilter)


Object   |   +-flash.filters.BitmapFilter     |     +-flash.filters.DropShadowFilter public class DropShadowFilter extends BitmapFilter

The DropShadowFilter class lets you add a drop shadow to a variety of objects in Flash. You have several options for the style of the drop shadow, including inner or outer shadow and knockout mode.

The use of filters depends on the object to which you apply the filter:

  • To apply filters to movie clips, text fields, and buttons at runtime, use the filters property. Setting the filters property of an object does not modify the object and can be undone by clearing the filters property.

  • To apply filters to BitmapData instances, use the BitmapData.applyFilter() method. Calling applyFilter() on a BitmapData object takes the source BitmapData object and the filter object and generates a filtered image as a result.

You can also apply filter effects to images and video at authoring time. For more information, see your authoring documentation.

If you apply a filter to a movie clip or button, the cacheAsBitmap property of the movie clip or button is set to true. If you clear all filters, the original value of cacheAsBitmap is restored.

This filter supports Stage scaling. However, general scaling, rotation, and skewing are not supported. If the object itself is scaled (if _xscale and _yscale are not 100%), the filter effect is not scaled. It is scaled only when the Stage is zoomed in.

A filter is not applied if the resulting image exceeds 2880 pixels in width or height. For example, if you zoom in on a large movie clip with a filter applied, the filter is turned off if the resulting image exceeds the limit of 2880 pixels.

Availability: ActionScript 1.0; Flash Player 8

See also

filters (MovieClip.filters property), cacheAsBitmap (MovieClip.cacheAsBitmap property), filters (Button.filters property), cacheAsBitmap (Button.cacheAsBitmap property), filters (TextField.filters property), applyFilter (BitmapData.applyFilter method)

Property summary

Modifiers

Property

Description

 

alpha :Number

The alpha transparency value for the shadow color.

 

angle :Number

The angle of the shadow.

 

blurX:Number

The amount of horizontal blur.

 

blurY:Number

The amount of vertical blur.

 

color:Number

The color of the shadow.

 

distance:Number

The offset distance for the shadow, in pixels.

 

hideObject:Boolean

Indicates whether or not the object is hidden.

 

inner:Boolean

Indicates whether or not the shadow is an inner shadow.

 

knockout:Boolean

Applies a knockout effect (TRue), which effectively makes the object's fill transparent and reveals the background color of the document.

 

quality:Number

The number of times to apply the filter.

 

strength:Number

The strength of the imprint or spread.


Properties inherited from class Object

constructor (Object.constructor property), __proto__ (Object.__proto__ property), prototype (Object.prototype property), __resolve (Object.__resolve property)


Constructor summary

Signature

Description

DropShadowFilter ([distance:Number], [angle:Number], [color:Number], [alpha:Number], [blurX:Number], [blurY:Number], [strength:Number], [quality:Number], [inner:Boolean], [knockout:Boolean], [hideObject:Boolean])

Creates a new DropShadowFilter instance with the specified parameters.


Method summary

Modifiers

Signature

Description

 

clone () : DropShadowFilter

Returns a copy of this filter object.


Methods inherited from class BitmapFilter

clone (BitmapFilter.clone method)


Methods inherited from class Object

addProperty (Object.addProperty method), hasOwnProperty (Object.hasOwnProperty method), isPropertyEnumerable (Object.isPropertyEnumerable method), isPrototypeOf (Object.isPrototypeOf method), registerClass (Object.registerClass method), toString (Object.toString method), unwatch (Object.unwatch method), valueOf (Object.valueOf method), watch (Object.watch method)


alpha (DropShadowFilter.alpha property)

public alpha : Number

The alpha transparency value for the shadow color. Valid values are 0 to 1. For example, .25 sets a transparency value of 25%. The default value is 1.

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the alpha property on a movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowAlpha"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.alpha = .4;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;     var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

angle (DropShadowFilter.angle property)

public angle : Number

The angle of the shadow. Valid values are 0 to 360° (floating point). The default value is 45.

The angle value represents the angle of the theoretical light source falling on the object and determines the placement of the effect relative to the object. If distance is set to 0, the effect is not offset from the object, and therefore the angle property has no effect.

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the angle property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowAngle"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.angle = 135;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;     var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

blurX (DropShadowFilter.blurX property)

public blurX : Number

The amount of horizontal blur. Valid values are 0 to 255 (floating point). The default value is 4. Values that are a power of 2 (such as 2, 4, 8, 16 and 32) are optimized to render more quickly than other values.

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the blurX property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowBlurX"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.blurX = 40;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;     var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

blurY (DropShadowFilter.blurY property)

public blurY : Number

The amount of vertical blur. Valid values are 0 to 255 (floating point). The default value is 4. Values that are a power of 2 (such as 2, 4, 8, 16 and 32) are optimized to render more quickly than other values.

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the blurY property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowBlurY"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.blurY = 40;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;     var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

clone (DropShadowFilter.clone method)

public clone() : DropShadowFilter

Returns a copy of this filter object.

Availability: ActionScript 1.0; Flash Player 8

Returns

flash.filters.DropShadowFilter - A new DropShadowFilter instance with all the properties of the original one.

Example

The following example creates three DropShadowFilter objects and compares them; filter_1 is created by using the DropShadowFilter constructor; filter_2 is created by setting it equal to filter_1; and clonedFilter is created by cloning filter_1. Notice that although filter_2 evaluates as being equal to filter_1, clonedFilter, even though it contains the same values as filter_1, does not.

import flash.filters.DropShadowFilter; var filter_1:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false); var filter_2:DropShadowFilter = filter_1; var clonedFilter:DropShadowFilter = filter_1.clone(); trace(filter_1 == filter_2); // true trace(filter_1 == clonedFilter); // false for(var i in filter_1) {   trace(">> " + i + ": " + filter_1[i]);   // >> clone: [type Function]   // >> hideObject: false   // >> strength: 1   // >> blurY: 16   // >> blurX: 16   // >> knockout: false   // >> inner: false   // >> quality: 3   // >> alpha: 0.8   // >> color: 0   // >> angle: 45   // >> distance: 15 } for(var i in clonedFilter) {   trace(">> " + i + ": " + clonedFilter[i]);   // >> clone: [type Function]   // >> hideObject: false   // >> strength: 1   // >> blurY: 16   // >> blurX: 16   // >> knockout: false   // >> inner: false   // >> quality: 3   // >> alpha: 0.8   // >> color: 0   // >> angle: 45   // >> distance: 15 }

To further demonstrate the relationships between filter_1, filter_2, and clonedFilter, the following example modifies the knockout property of filter_1. Modifying knockout demonstrates that the clone() method creates a new instance based on the values of filter_1 instead of pointing to them in reference.

import flash.filters.DropShadowFilter; var filter_1:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false); var filter_2:DropShadowFilter = filter_1; var clonedFilter:DropShadowFilter = filter_1.clone(); trace(filter_1.knockout); // false trace(filter_2.knockout); // false trace(clonedFilter.knockout); // false filter_1.knockout = true; trace(filter_1.knockout); // true trace(filter_2.knockout); // true trace(clonedFilter.knockout); // false

color (DropShadowFilter.color property)

public color : Number

The color of the shadow. Valid values are in hexadecimal format 0xRRGGBB. The default value is 0x000000.

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the color property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowColor"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.color = 0xFF0000;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;     var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

distance (DropShadowFilter.distance property)

public distance : Number

The offset distance for the shadow, in pixels. The default value is 4 (floating point).

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the distance property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowDistance"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.distance = 40;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;     var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

DropShadowFilter constructor

public DropShadowFilter([distance:Number], [angle:Number], [color:Number],   [alpha:Number], [blurX:Number], [blurY:Number], [strength:Number],   [quality:Number], [inner:Boolean], [knockout:Boolean],   [hideObject:Boolean])

Creates a new DropShadowFilter instance with the specified parameters.

Availability: ActionScript 1.0; Flash Player 8

Parameters

distance:Number [optional] - The offset distance for the shadow, in pixels. The default value is 4 (floating point).

angle:Number [optional] - The angle of the shadow, 0 to 360° (floating point). The default value is 45.

color:Number [optional] - The color of the shadow, in hexadecimal format 0xRRGGBB. The default value is 0x000000.

alpha:Number [optional] - The alpha transparency value for the shadow color. Valid values are 0 to 1. For example, .25 sets a transparency value of 25%. The default value is 1.

blurX:Number [optional] - The amount of horizontal blur. Valid values are 0 to 255 (floating point). The default value is 4. Values that are a power of 2 (such as 2, 4, 8, 16 and 32) are optimized to render more quickly than other values.

blurY:Number [optional] - The amount of vertical blur. Valid values are 0 to 255 (floating point). The default value is 4. Values that are a power of 2 (such as 2, 4, 8, 16 and 32) are optimized to render more quickly than other values.

strength:Number [optional] - The strength of the imprint or spread. The higher the value, the more color is imprinted and the stronger the contrast between the shadow and the background. Valid values are 0 to 255. The default is 1.

quality:Number [optional] - The number of times to apply the filter. Valid values are 0 to 15. The default value is 1, which is equivalent to low quality. A value of 2 is medium quality, and a value of 3 is high quality.

inner:Boolean [optional] - Indicates whether or not the shadow is an inner shadow. A value of TRue specifies an inner shadow. The default is false, an outer shadow (a shadow around the outer edges of the object).

knockout:Boolean [optional] - Applies a knockout effect (TRue), which effectively makes the object's fill transparent and reveals the background color of the document. The default is false (no knockout).

hideObject:Boolean [optional] - Indicates whether or not the object is hidden. A value of TRue indicates that the object itself is not drawn; only the shadow is visible. The default is false (show the object).

Example

The following example instantiates a new DropShadowFilter instance and applies it to a flat, rectangular shape.

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 = .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; function createRectangle(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);   mc._x = 20;   mc._y = 20;   return mc; }

hideObject (DropShadowFilter.hideObject property)

public hideObject : Boolean

Indicates whether or not the object is hidden. The value true indicates that the object itself is not drawn; only the shadow is visible. The default is false (show the object).

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the hideObject property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowHideObject"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.hideObject = true;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;   var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

inner (DropShadowFilter.inner property)

public inner : Boolean

Indicates whether or not the shadow is an inner shadow. The value true indicates an inner shadow. The default is false, an outer shadow (a shadow around the outer edges of the object).

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the inner property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowInner"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.inner = true;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;   var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

knockout (DropShadowFilter.knockout property)

public knockout : Boolean

Applies a knockout effect (true), which effectively makes the object's fill transparent and reveals the background color of the document. The default is false (no knockout).

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the knockout property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowKnockout"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.knockout = true;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;   var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

quality (DropShadowFilter.quality property)

public quality : Number

The number of times to apply the filter. Valid values are 0 to 15. The default value is 1, which is equivalent to low quality. A value of 2 is medium quality, and a value of 3 is high quality. Filters with lower values are rendered more quickly.

For most applications, a quality value of 1, 2, or 3 is sufficient. Although you can use additional numeric values up to 15 to achieve different effects, higher values are rendered more slowly. Instead of increasing the value of quality, you can often get a similar effect, and with faster rendering, by simply increasing the values of blurX and blurY.

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the quality property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowQuality"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.quality = 0;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;   var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }

strength (DropShadowFilter.strength property)

public strength : Number

The strength of the imprint or spread. The higher the value, the more color is imprinted and the stronger the contrast between the shadow and the background. Valid values are from 0 to 255. The default is 1.

Availability: ActionScript 1.0; Flash Player 8

Example

The following example changes the strength property on an existing movie clip when a user clicks it.

import flash.filters.DropShadowFilter; var mc:MovieClip = createDropShadowRectangle("DropShadowStrength"); mc.onRelease = function() {   var filter:DropShadowFilter = this.filters[0];   filter.strength = .6;   this.filters = new Array(filter); } function createDropShadowRectangle(name:String):MovieClip {   var art:MovieClip = this.createEmptyMovieClip(name,   this.getNextHighestDepth());   var w:Number = 100;   var h:Number = 100;   art.beginFill(0x003366);   art.lineTo(w, 0);   art.lineTo(w, h);   art.lineTo(0, h);   art.lineTo(0, 0);   art._x = 20;   art._y = 20;   var filter:DropShadowFilter = new DropShadowFilter(15, 45, 0x000000, .8,   16, 16, 1, 3, false, false, false);   var filterArray:Array = new Array();   filterArray.push(filter);   art.filters = filterArray;   return art; }



ActionScript 2.0 Language Reference for Macromedia Flash 8
ActionScript 2.0 Language Reference for Macromedia Flash 8
ISBN: 0321384040
EAN: 2147483647
Year: 2004
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net