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 pointer’s current position on the Stage.
Содержание 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...