512
Animation, Filters, and Drawings
To create a drop shadow that follows the mouse pointer:
1.
Create a new Flash document and save it as
dropshadowmouse.fla
.
2.
Add the following ActionScript to Frame 1 of the Timeline:
import flash.filters.DropShadowFilter;
System.security.allowDomain("http://www.helpexamples.com");
var dropShadow:DropShadowFilter = new DropShadowFilter(4, 45, 0x000000,
0.8, 10, 10, 2, 2);
// Load and position the image on the Stage.
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip):Void {
target_mc._x = (Stage.width - target_mc._width) / 2;
target_mc._y = (Stage.height - target_mc._height) / 2;
};
this.createEmptyMovieClip("img_mc", 10);
var img_mcl:MovieClipLoader = new MovieClipLoader();
img_mcl.addListener(mclListener);
img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",
img_mc);
// When mouse moves, recalculate the position of the drop shadow.
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function():Void {
var p1:Number = img_mc._y - _ymouse;
var p2:Number = img_mc._x - _xmouse;
var degrees:Number = Math.atan2(p1, p2) / (Math.PI / 180);
dropShadow.distance = Math.sqrt(Math.pow(p1, 2) + Math.pow(p2, 2)) *
0.5;
dropShadow.blurX = dropShadow.distance;
dropShadow.blurY = dropShadow.blurX;
dropShadow.angle = degrees - 180;
img_mc.filters = [dropShadow];
};
Mouse.addListener(mouseListener);
The first section of this code defines a drop shadow instance, loads an external image, and
repositions the image at the center of the Stage. The second section of code defines a
mouse listener, which you call whenever the user moves the mouse pointer around the
Stage. Whenever the mouse moves, the event handler recalculates the distance and angle
between the mouse pointer and the upper-left corner of the image. Based on this
calculation, the drop shadow filter is reapplied to the movie clip.
3.
Select Control > Test Movie to test the Flash document.
When you run the SWF file, the drop shadow follows the mouse pointer. The closer you
move the mouse pointer to the upper-left corner of the image on the Stage, the less of a
blur effect is applied to the image. As the mouse pointer moves further from the upper-left
corner of the image, the drop shadow effect becomes more apparent.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...