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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To use the convolution filter to modify an image's color:
1.
Create a new Flash document and save it as convolution.fla.
2.
Add the following ActionScript to Frame 1 of the Timeline:
import flash.filters.ConvolutionFilter;
import flash.display.BitmapData;
this.createEmptyMovieClip("shape_mc", 1);
shape_mc.createEmptyMovieClip("holder_mc", 1);
var imageLoader:MovieClipLoader = new MovieClipLoader();
imageLoader.loadClip("http://www.helpexamples.com/flash/images/
image1.jpg", shape_mc.holder_mc);
var matrixArr:Array = [1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 16, 6, 24, 36,
24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1];
var convolution:ConvolutionFilter = new ConvolutionFilter(5, 5,
matrixArr);
shape_mc.filters = [convolution];
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function():Void {
convolution.divisor = (_xmouse / Stage.width) * 271;
convolution.bias = (_ymouse / Stage.height) * 100;
shape_mc.filters = [convolution];
};
Mouse.addListener(mouseListener);
The preceding code is separated into three sections. The first section imports two classes:
ConvolutionFilter and BitmapData. The second section creates a nested movie clip and
uses a movie clip loader object to load an image into the nested movie clip. A convolution
filter object is created and applied to the shape_mc movie clip. The final section of code
defines a mouse listener object that modifies the convolution filter's divisor and bias
properties based on the current position of the mouse pointer and reapplies the
convolution filter to the
3.
Select Control > Test Movie to test the Flash document.
Moving the mouse pointer along the x-axis of the Stage modifies the filter's divisor,
whereas moving the mouse pointer along the y-axis of the Stage modifies the filter's bias.
Using the displacement map filter
The DisplacementMapFilter class uses the pixel values from the specified BitmapData object
(called the displacement map image) to perform a displacement of an instance that's on the
Stage, such as a movie clip instance or a bitmap data instance. You can use this filter to achieve
a warped or mottled effect on a specified instance.
528
Animation, Filters, and Drawings
movie clip.
shape_mc

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash 8

Table of Contents