508
Animation, Filters, and Drawings
To blur an image based on the mouse pointer’s position:
1.
Create a new Flash document and save it as
dynamicblur.fla
.
2.
Add the following code to Frame 1 of the Timeline:
import flash.filters.BlurFilter;
System.security.allowDomain("http://www.helpexamples.com");
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
// Center the target_mc movie clip on the Stage.
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);
var blur:BlurFilter = new BlurFilter(10, 10, 2);
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function():Void {
/* Moving the pointer to the center of the Stage sets the blurX and
blurY properties to 0%. */
blur.blurX = Math.abs(_xmouse - (Stage.width / 2)) / Stage.width * 2 *
255;
blur.blurY = Math.abs(_ymouse - (Stage.height / 2)) / Stage.height * 2
* 255;
img_mc.filters = [blur];
};
Mouse.addListener(mouseListener);
The first section of this code loads and positions a dynamically loaded image on the Stage.
The second section defines a listener that is called whenever the mouse moves. You
calculate the amount of horizontal and vertical blurring based on the mouse pointer’s
current position on the Stage. The further you move the pointer away from the center of
the Stage, the more blurring is applied to the instance.
Содержание 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...