EasyManua.ls Logo

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

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...
Creating bitmaps with the BitmapData class 535
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/BitmapData.
The following procedure dynamically loads a JPEG image onto the Stage, and uses the
BitmapData class to create a noise effect, similar to static on a television. The noise effect is
redrawn with a random pattern every 100 milliseconds (1/10 of a second). Moving the mouse
pointer along the x-axis and y-axis affects how much static is drawn at every interval.
To create a noise effect with the BitmapData class:
1. Create a new Flash document and save it as noise.fla.
2. Add the following ActionScript to Frame 1 of the Timeline:
import flash.display.BitmapData;
this.createTextField("status_txt", 90, 0, 0, 100, 20);
status_txt.selectable = false;
status_txt.background = 0xFFFFFF;
status_txt.autoSize = "left";
function onMouseMove() {
status_txt._x = _xmouse;
status_txt._y = _ymouse-20;
updateAfterEvent();
}
this.createEmptyMovieClip("img_mc", 10);
img_mc.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");
var noiseBmp:BitmapData = new BitmapData(Stage.width, Stage.height,
true);
this.attachBitmap(noiseBmp, 20);
setInterval(updateNoise, 100);
var grayScale:Boolean = true;
function updateNoise():Void {
var low:Number = 30 * _xmouse / Stage.width;
var high:Number = 200 * _ymouse / Stage.height;
status_txt.text = "low:" + Math.round(low) + ", high:" +
Math.round(high);
noiseBmp.noise(Math.round(Math.random() * 100000), low, high, 8,
true);
}
This code creates a text field with the instance name status_txt, which follows the
mouse pointer and displays the current values for the
high and low parameters for the
noise() method. The setInterval() function changes the noise effect, which is
updated every 100 milliseconds (1/10 of a second), by continuously calling the
updateNoise() function. The high and low parameters for the noise() method are
determined by calculating the pointers current position on the Stage.

Table of Contents

Related product manuals