先看效果:
下面是代码:
import flash.filters.ColorMatrixFilter;
import mx.transitions.Tween;
import mx.transitions.easing.*;
var nowI:Number;
smallbg.targetx = (Stage.width-smallbg._width)/2;
function aa(i:Number) {
function brightnessWatcher(prop:String, oldVal:Number, newVal:Number, img_mc:MovieClip):Number {
var brightness_array:Array = [1, 0, 0, 0, newVal, 0, 1, 0, 0, newVal, 0, 0, 1, 0, newVal, 0, 0, 0, 1, 0];
colorMF = new ColorMatrixFilter(brightness_array);
img_mc.filters = [colorMF];
return newVal;
}
this.createEmptyMovieClip("img_mc", 0);
img_mc.attachMovie("pic"+i, "pic"+i, i);
img_mc._x = (Stage.width-img_mc._width)/2;
img_mc._y = (Stage.height-img_mc._height)-40;
img_mc.watch("brightness", brightnessWatcher, img_mc);
var t:Object = new Tween(img_mc, "brightness", Elastic.easeOut, 100, 0, 5, true);
nowI = i;
}
aa(1);
for (j=1; j<7; j++) {
this.smallbg["btnmc"+j].no = j;
this.smallbg["btnmc"+j]._alpha = 80;
this.smallbg["btnmc"+j].useHandCursor = false;
this.smallbg["btnmc"+j].onRelease = function() {
a = this.no;
if (nowI != a) {
aa(a);
}
};
this.smallbg["btnmc"+j].onRollOver = function() {
this._alpha = 100;
};
this.smallbg["btnmc"+j].onRollOut = function() {
this._alpha = 80;
};
}
onEnterFrame = function () {
smallbg._x += (smallbg.targetx-smallbg._x)*0.2;
if (Math.abs(smallbg.targetx-smallbg._x)<=0.2) {
smallbg._x = smallbg.targetx;
delete onEnterFrame;
}
};
stop();
//////////////以下为自动调用外部图片的代码/////////////////////////////////////////////////////////////////////////////////////////////
function aaa(i:Number) {
this.createEmptyMovieClip("img_mc", 10);
var img_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip):Void {
// 使影片剪辑实例在舞台上居中
target_mc._x = (Stage.width-target_mc._width)/2;
target_mc._y = Stage.height-target_mc._height;
target_mc.watch("brightness", brightnessWatcher, target_mc);
// 为 target_mc 影片剪辑添加动画效果,使其亮度在 -100 到 +100 之间变化
var t:Object = new Tween(target_mc, "brightness", Elastic.easeOut, 100, 0, 3, true);
////////设置自动播放影片的代码////////////////////////////////////////////////////////////
//t.onMotionFinished = function() {
//if (i<6) {
//i = i+1;
//} else {
//i = 1;
//}
//trace(ID);
//ID = setInterval(aa, 3000, i);
//};
////////////////////////////////////////////////////////////////////////
};
img_mcl.addListener(mclListener);
img_mcl.loadClip("img/photo"+i+".jpg", img_mc);
function brightnessWatcher(prop:String, oldVal:Number, newVal:Number, target_mc:MovieClip):Number {
var brightness_array:Array = [1, 0, 0, 0, newVal, 0, 1, 0, 0, newVal, 0, 0, 1, 0, newVal, 0, 0, 0, 1, 0];
colorMF = new ColorMatrixFilter(brightness_array);
target_mc.filters = [colorMF];
return newVal;
}
nowI = i;
//if (ID != undefined) {
//clearInterval(ID);
//}
//trace("lID="+ID)
}
源文件下载: 图片效果系列之二.rar