Question

I know I can apply a Color Filter in Flash by hand, and then copy it to other movieclips dynamically, like so:

newMovieClip.filters = oldMovieClip.filters;

What I would love to do now is be able to check if two movieclips have the same filter.
Something like this:

if (newerMovieClip.filters == oldMovieClip.filters)

...that always comes out as false, even if the two have the same filter. I know I can make this work if I use a colorTransform instead, but I can't in this case. The graphics have lines and shading that are all changing color together, and the brightness/hue/contrast are all important so filters are key. (What I'm doing: I have clothing items in the menu that the user "colors" by picking a filtered button from a palette I made. When they click the item, and it's not already on the avatar in that color, I want it to appear and/or turn that color. If it's already on the avatar and the same color, I want it to come off... hence the filter check)

Was it helpful?

Solution

EDIT: I see now that you are only dealing with a Color Filter. Ahh. I understand what trying to do now.

this can make things a little easier if that is the only filter on each Movieclip.

In this case we can get each ColorMatrixFilter of each movieclip by moiveclip.filters[0]

then:

function compareColorFilters(a:ColorMatrixFilter, b:ColorMatrixFilter) : Boolean
{
   var length:uint = (a.matrix.length > b.matrix.length)?a.matrix.length:b.matrix.length;
   for(var i:uint = 0; i < length; ++i)
   {
       if(a.matrix[i] != b.matrix[i]) { return false; }
   }
 return true;
}

then to compare to movieclips would be

if(compareColorFilters(ColorMatrixFilter(oldClip.filters[0]), ColorMatrixFilter(newClip.filters[0])) {
        //do stuff
}

As you can see you are getting each ColorMatrixFilters from each moveiClip. Then comparing there matrices (which is just an array) element by element. If the Matrices are the same... The colors, brightness, and hues are also the exact same. If confused at all by this, leave a comment.

Hope this helps!

-Travis

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top