MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 508

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

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.
508
Animation, Filters, and Drawings

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents