[F8] filters_problem!

Hi!

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 flash.filters.BlurFilter;
var bf:BlurFilter = new BlurFilter(10, 10, 1);
target_mc.filters = [bf];
function noblur(target){
target_mc.onRollOver = function() {
	this.onEnterFrame = function() {
		if (bf.blurX>1) {
			bf.blurX--;
			bf.blurY --;
		} else {
			delete this.onEnterFrame;
		} 
		this.filters = [bf];
		target.onRollOut = function() {
			this.onEnterFrame = function() {
				this.filters = [bf];
				if (bf.blurX<10) {
					bf.blurX++;
					bf.blurY=bf.blurX;
				} else {
					delete this.onEnterFrame;
				}
			};
		};
	};
};
}

Thanks in advanced.

any advice or comment?

I maybe don’t understand your question exactly but, if you have let’s say 5 MCs called target1 trough target5 you apply the filter like

import flash.filters.BlurFilter;
var bf:BlurFilter = new BlurFilter(10, 10, 1);
for (var x = 1;x<=5;x++){
this["target"+x].filters = [bf];
}

As easy as that…

Thanks for reply!
Surely it is easy!

But, what do I do with the onRollOver and onRollOut?
Sorry, but I’m not that …intelligent!


import flash.filters.BlurFilter;
var bf:BlurFilter = new BlurFilter(10, 10, 1);
for (var x = 1; x<=5; x++) {
	this["target"+x].filters = [bf];
}
["target"+x]onRollOver = function() {
	this.onEnterFrame = function() {
		if (bf.blurX>1) {
			bf.blurX--;
			bf.blurY--;
		} else {
			delete this.onEnterFrame;
		}
		this.filters = [bf];
		["target"+x]onRollOut = function() {
			this.onEnterFrame = function() {
				this.filters = [bf];
				if (bf.blurX<10) {
					bf.blurX++;
					bf.blurY = bf.blurX;
				} else {
					delete this.onEnterFrame;
				}
			};
		};
	};
};

import flash.filters.BlurFilter;
for (var x = 1; x <= 7; x++) {
 var mc:MovieClip = this["target" + x];
 mc.bf = new BlurFilter(10, 10, 1);
 mc.onRollOver = function() {
  this.onEnterFrame = function() {
   if (this.bf.blurX <= 0) {
    trace(this.bf.blurX);
    delete this.onEnterFrame;
   }
   this.bf.blurX = this.bf.blurY--;
   this.filters = [this.bf];
  };
 };
 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];
  };
 };
 this["target" + x].onRollOut();
}

Thank you very much!

Could explain a little bit, please?

:snug:

Sure thing:

//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!!!

:hoser:

That’s nice from you!

You’re the man, as always!

:wink: