You could also create an animated brightness effect by combining the Tween class with the
ColorMatrixFilter class, as the next procedure shows.
To animate the brightness level of an instance by using the Tween class:
1.
Create a new Flash document and save it as brightnesstween.fla.
2.
Add the following ActionScript to Frame 1 of the Timeline:
import flash.filters.ColorMatrixFilter;
import mx.transitions.Tween;
import mx.transitions.easing.*;
System.security.allowDomain("http://www.helpexamples.com");
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip):Void {
// center movie clip instance on Stage
target_mc._x = (Stage.width - target_mc._width) / 2;
target_mc._y = (Stage.height - target_mc._height) / 2;
target_mc.watch("brightness", brightnessWatcher, target_mc);
// animate the target_mc movie clip between -100 and +100 brightness
var t:Object = new Tween(target_mc, "brightness", Elastic.easeOut,
100, -100, 3, true);
t.onMotionFinished = function() {
this.yoyo();
};
};
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);
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];
target_mc.filters = [new ColorMatrixFilter(brightness_array)];
return newVal;
};
526
Animation, Filters, and Drawings
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?