EasyManua.ls Logo

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

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...
536 Animation, Filters, and Drawings
3. Select Control > Test Movie to test the document.
Moving the mouse pointer along the x-axis affects the
low parameter; moving the mouse
pointer along the y-axis affects the
high parameter.
The BitmapData class also lets you distort a dynamically loaded image by using a
combination of a
perlinNoise() method effect and a displacement map filter. The following
procedure shows this.
To apply a displacement map filter to an image:
1. Create a new Flash document and save it as displacement.fla.
2. Add the following ActionScript to Frame 1 of the Timeline:
// Import classes.
import flash.filters.DisplacementMapFilter;
import flash.display.BitmapData;
import flash.geom.Point;
// Create a clip and a nested clip.
var shapeClip:MovieClip = this.createEmptyMovieClip("shapeClip", 1);
shapeClip.createEmptyMovieClip("holderClip", 1);
// Load JPEG.
var imageLoader:MovieClipLoader = new MovieClipLoader();
imageLoader.loadClip("http://www.helpexamples.com/flash/images/
image4.jpg", shapeClip.holderClip);
// Create BitmapData instance.
var perlinBmp:BitmapData = new BitmapData(Stage.width, Stage.height);
perlinBmp.perlinNoise(Stage.width, Stage.height, 10,
Math.round(Math.random() * 100000), false, true, 1, false);
// Create and apply the displacement map filter.
var displacementMap:DisplacementMapFilter = new
DisplacementMapFilter(perlinBmp, new Point(0, 0), 1, 1, 100, 100,
"color", 1);
shapeClip.filters = [displacementMap];
// Create and apply a listener.
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function():Void {
perlinBmp.perlinNoise(Stage.width, Stage.height, 10,
Math.round(Math.random() * 100000), false, true, 1, false);
shapeClip.filters = [displacementMap];
}
Mouse.addListener(mouseListener);

Table of Contents

Related product manuals