Again, I will try to keep this really small…
Let’s assume we have a MovieClip instance to which we assign a bunch of filters, out of which we have a BlurFilter that has to be updated each frame. This should be quite a common task to do..
The biggest issue with good ol’ Adobe’s “filters” property of the MovieClip(or any other DisplayContainer that can handle BitmapFilter(s)) is that it is actually only taken in account during setting. Let me make this more clear, “filters” is a property that has a setter, in which implementation Adobe gathers all the filters that you provide (via the Array). This means that once you set the property, you cannot change the values (eg. blurX in our example), in fact you can, but the new values will not be taken in account when rendering the clip. This, you may think, can be easily fixable, just reset the filters property with the same array of filters. Actually is not that simple, because as what it feels to me to be another optimization gone bad on Adobe’s side, they also check whether the reference to the Array of filters/all filter references inside the Array, point to the same objects that the previous Array did, so just reassigning the Array to the property does not work.
However there is another quick fix, BitmapFilter implements a method called clone(), which does exactly what it’s name suggests, clone a filter or in other words, create a NEW filter object and copy all the clonee’s properties to this one. So, we can hack around this “optimization” of Adobe, by cloning one of the filters in the array, remove the clonee and add the cloned instance, something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | .. //somewhere, create the mc, add some filters to it mc.filters = [myBlurFilter, myGlowFilter]; .. // now we need to change the blurX property of the myBlurFilter myBlurFilter.blurX = 100; //get the array of filters so we can clone our myBlurFilter var installedFilters:Array = mc.filters; //first remove the clonee from the array installedFilters.splice(installedFilters.indexOf(myBlurFilter),1); //clone and add the clone array installedFilters.push(myBlurFilter.clone()); //we bypassed Adobe's checks, set the new filter, without altering the other filters mc.filters = installedFilters; |
laterz, gatorz,
dw.