EasyManua.ls Logo

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

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...
510 Animation, Filters, and Drawings
To use the drop shadow filter:
1. Create a new Flash document and save it as dropshadow.fla.
2. Add the following ActionScript to Frame 1 of the Timeline:
// import the filter classes
import flash.filters.DropShadowFilter;
// create a movie clip called shapeClip
this.createEmptyMovieClip("shapeClip", 1);
// use the Drawing API to draw a shape
with (shapeClip) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(100, 0);
lineTo(100, 100);
lineTo(0, 100);
lineTo(0, 0);
endFill();
}
// position the shape
shapeClip._x = 100;
shapeClip._y = 100;
// click the square, increase shadow strength
shapeClip.onPress = function():Void {
dropShadow.strength++;
shapeClip.filters = [dropShadow];
};
// create a filter
var dropShadow:DropShadowFilter = new DropShadowFilter(4, 45, 0x000000,
0.4, 10, 10, 2, 3);
var mouseListener:Object = new Object();
// create and apply a listener that controls the filter when the mouse
moves
mouseListener.onMouseMove = function():Void {
dropShadow.distance = (_xmouse / Stage.width) * 50 - 20;
dropShadow.blurX = (_ymouse / Stage.height) * 10;
dropShadow.blurY = dropShadow.blurX;
shapeClip.filters = [dropShadow];
};
Mouse.addListener(mouseListener);
The first section of code creates a new movie clip and uses the Drawing API to draw a red
square. The second section of code defines a mouse listener, which is called whenever the
mouse moves. The mouse listener calculates the drop shadow’s distance and level of
blurring based on the current x and y positions of the mouse pointer, and reapplies the
drop shadow filter. If you click the red square, the drop shadows strength increases.

Table of Contents

Related product manuals