I would like to know if there’s a way to apply a filter to many mc’s.
I’ve been looking for tutorials and examples, but the filter is applied only to one item.
So I would like to know if I can use a function to apply the same filters with to many mc’s.
I know how to apply only to one, but should I use the same code and repeat it for all the rest?
//import BlurFilter class
import flash.filters.BlurFilter;
//loop thorugh the clips, in this case 1 through 7
for (var x = 1; x <= 7; x++) {
//store the resolved movie clip as mc so we don't have to write as much
var mc:MovieClip = this["target" + x];
//give the movie clip its own blur filter, otherwise modifiy the filter would affect all of the movie clips
mc.bf = new BlurFilter(10, 10, 1);
//set function to execute onRollOver
mc.onRollOver = function() {
//onEnterFrame yadda yadda yadda
this.onEnterFrame = function() {
//if the mc's blur filter is less than or equal to 0, delete the onEnterFrame function
if (this.bf.blurX <= 0) {
trace(this.bf.blurX);
delete this.onEnterFrame;
}
//set blurX equal blurY minus equal 1
this.bf.blurX = this.bf.blurY--;
//set filter property of movie clip
this.filters = [this.bf];
};
};
//same deal as onRollOver but in reverse ;)
mc.onRollOut = function() {
this.onEnterFrame = function() {
if (this.bf.blurX >= 10) {
trace(this.bf.blurX);
delete this.onEnterFrame;
}
this.bf.blurX = this.bf.blurY++;
this.filters = [this.bf];
};
};
//initialize the clip by calling its onRollOut function (applies filter)
//alternatively you could've written || mc.filters = [mc.bf] || but this way looks better :)
mc.onRollOut();
//delete the temporary variable (which up to this point wasn't temporary :) )
delete mc;
}
//test the movie and watch the 7 movie clips and their filters animate
//THE END!!!