Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Animation, Filters, and Drawings > Working with filters using ActionScript > Using the glow filter | |||
The GlowFilter class lets you add a glow effect to various objects in Flash. The glow algorithm is based on the same box filter that is the blur filter uses (see Using the blur filter). You can set the style of the glow in several ways, including inner or outer glow and knockout mode. The glow filter is similar to the drop shadow filter with the distance and angle properties of the drop shadow set to 0.
For more information on the glow filter, see GlowFilter (flash.filters.GlowFilter) in the ActionScript 2.0 Language Reference.
The following procedure demonstrates how you can apply a glow filter to a dynamically created movie clip on the Stage. Moving your mouse pointer around the Stage causes the movie clip's blur to change, and clicking the dynamically created shape causes the filter's strength to increase.
import flash.filters.GlowFilter;
this.createEmptyMovieClip("shapeClip", 10);
with (shapeClip) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(100, 0);
lineTo(100, 100);
lineTo(0, 100);
lineTo(0, 0);
endFill();
}
shapeClip._x = 100;
shapeClip._y = 100;
shapeClip.onPress = function():Void {
glow.strength++;
shapeClip.filters = [glow];
};
var glow:GlowFilter = new GlowFilter(0xCC0000, 0.5, 10, 10, 2, 3);
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function():Void {
glow.blurX = (_xmouse / Stage.width) * 255;
glow.blurY = (_ymouse / Stage.width) * 255;
shapeClip.filters = [glow];
};
Mouse.addListener(mouseListener);
This code uses the Drawing API to draw a square on the Stage, and applies a glow filter to the shape. Whenever the mouse pointer moves along the x-axis or y-axis, the glow filter's blur is calculated and applied to the shape.
The amount of horizontal and vertical blurring is calculated by the mouse pointer's current _xmouse and _ymouse position. As you move the mouse pointer to the upper-left corner of the Stage, the amount of horizontal and vertical blurring decreases. Conversely, as the mouse pointer moves to the lower-right corner of the Stage, the amount of horizontal and vertical blurring increases.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000978.html