views:

78

answers:

2

Is there any way of applying a ColorMatrixFilter to one rectangular area of a DisplayObject, leaving the rest untouched? The DO is a container, and the user interacts with objects in it, so taking snapshots to change its appearance isn't an option.

A: 

No can do... see this: http://stackoverflow.com/questions/1189226/apply-filter-to-everything-in-as3/1193319

UPDATE: As the referenced post explains, you could either put everything you need to apply the filter to in a different container than the rest, or (and I think this is more usefull in your case) put a Bitmap on top of all you interface, and draw/applyFilter it when something changes.

The Bitmap won't interrupt mouse events (it's not an InteractiveObject), and you would be able to control how, when and what sub-area of you filtered area to update... specially with ColorMatrixFilter, as it doesn't affect sorrounding pixels. Its a bit of work to setup, but it pays off ;)

Good luck!

Cay
I've marked this down in case anyone thinks that the referenced post answers the question. The OP there has code which for some reason fails to apply a filter to a container and all its children. But that's not my problem - contrary to the suggestion in this answer, it's quite easy. My problem is that the filter is applied to the *whole* container (and its children), and I want only a region of it to be filtered.
mauricen
Well, I think I answered your question: you can't apply filters to a rectangular area of a DisplayObject. The referenced thread explains quite accordingly how filters work, and the possible workarounds you could use. I'll update my answer with a more detailed workaround.
Cay
+2  A: 

One potential method of pulling the off would be to have two copies of the object, one above the other. The top object would have the filter applied to it and also have it's scrollRect property set so as to mask it out to the rectaglw you wish. The rear object would then show the rest of the object in it's unaltered form.

Branden Hall
That's worth exploring - thanks! I can see this working if I kept two copies not only of the container but also of its display list, and maintained their changing properties in parallel. It's frustrating that such an elaborate hack is necessary when changing a couple of lines in ColorMatrixFilter would do the job. But Adobe have closed the filters package to subclassing.
mauricen