EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 514

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
514 Animation, Filters, and Drawings
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 clips blur to change, and clicking the dynamically created shape causes the filter’s
strength to increase.
To use the glow filter:
1. Create a new Flash document and save it as glowfilter.fla.
2. Add the following ActionScript code to Frame 1 of the Timeline:
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.

Table of Contents

Related product manuals