I am trying to apply a color matrix filter to all movie clips in a movie. I would like to do this without knowing the instance name of any of the clips. Does anyone know a way to loop through all the movie clips of a scene regardless of the names or number of clips.
for (var prop in this) {
if (this[prop] instanceof MovieClip) {
this[prop].filters = new Array(myColorMatrixFilter);
}
}
Thanks, that’s great code. It works perfect.
Here is what I ended up with.
import flash.filters.ColorMatrixFilter;
var theColorMatrixFilter = new flash.filters.ColorMatrixFilter();
var theBWMatrixFilter = new flash.filters.ColorMatrixFilter();
var bwFilters:Array = new Array(theBWMatrixFilter);
var bwFilterMatrix:Array = new Array(0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0, 0, 0, 1, 0);
bwFilters[0].matrix = bwFilterMatrix;
var colorFilters:Array = new Array(theColorMatrixFilter);
var colorFilterMatrix:Array = new Array(1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0);
colorFilters[0].matrix = colorFilterMatrix;
bwBT.onPress = function(){
for (var object in _root) {
if (_root[object] instanceof MovieClip) {
_root[object].filters = bwFilters;
}
}
}
colorBT.onPress = function(){
for (var object in _root) {
if (_root[object] instanceof MovieClip) {
_root[object].filters = colorFilters;
}
}
}