2007/01/30 | 图书摘录九:使用 BitmapData 类创建杂点效果
类别(编程资源) | 评论(0) | 阅读(83) | 发表于 13:04

使用 BitmapData 类创建杂点效果:
1. 创建一个新的 Flash 文档,并将它保存为 noise.fla。
2. 将下面的 ActionScript 添加到时间轴中的第 1 帧:
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();
}


注:就是当是BitmapData 类的一个应用实例吧。

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);
}
此代码使用实例名称  status_txt  创建一个文本字段,该字段跟随鼠标指针并为noise() 方法显示 high 和 low 参数的当前值。setInterval() 函数可更改杂点效果,杂点效果通过连续调用 updateNoise() 函数每隔 100 毫秒(一秒的 1/10)更新一次。
noise() 方法的 high 和 low 参数通过计算指针在舞台上的当前位置来确定。
3. 选择“控制” >“测试影片”来测试该文档。
沿 x 轴移动鼠标指针将影响 low 参数;而沿 y 轴移动鼠标指针将影响 high 参数。
0

评论Comments