为动态遮罩添加动画效果:
1. 创建一个新的 Flash 文档,并将它保存为 dynmask.fla。
2. 将下面的 ActionScript 添加到时间轴中的第 1 帧:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc._visible = false;
// 在舞台上将图像居中。
target_mc._x = (Stage.width - target_mc._width) / 2;
target_mc._y = (Stage.height - target_mc._height) / 2;
var maskClip:MovieClip = target_mc.createEmptyMovieClip("mask_mc", 20);
with (maskClip) {
// 绘制与加载的图像大小相同的遮罩。
beginFill(0xFF00FF, 100);
moveTo(0, 0);
lineTo(target_mc._width, 0);
lineTo(target_mc._width, target_mc._height);
lineTo(0, target_mc._height);
lineTo(0, 0);
endFill();
}
target_mc.setMask(maskClip);
target_mc._visible = true;
var mask_tween:Object = new Tween(maskClip, "_yscale", Strong.easeOut, 0, 100, 2, true);
};
this.createEmptyMovieClip("img_mc", 10);
var img_mcl:MovieClipLoader = new MovieClipLoader();
img_mcl.addListener(mclListener);
img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);
注:Tween 类的一个实例。