Managing filters (applying and removing randomly)

Hi guys,

Here is some code I thought you guys would like.
Ever had trouble with adding and removing different filters to a display object and bumping into that wall with that annoying filters copy behavior?

Here is a nice way to get rid of all your troubles.

[AS]
var filterDic=new Dictionary();
DisplayObject.prototype.applyFilter = function (filter) {
if (!filterDic[this]) filterDic[this]=this.filters;
filterDic[this].push(filter); trace(“apply”+(filterDic[this].length-1))
this.filters=filterDic[this];
}
DisplayObject.prototype.removeFilter = function (filter) { trace(filterDic[this].indexOf(filter));
filterDic[this].splice(filterDic[this].indexOf(filter), 1);
this.filters=filterDic[this];
}

//Example use
var glowFilter = new GlowFilter(0x00FFFF, 1.0, 8, 8, 6, 2);
var redFilter = new ColorMatrixFilter([ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
DO.applyFilter (glowFilter);
DO.applyFilter (redFilter );
DO.removeFilter (glowFilter); //red stays!![/AS]

I didn’t write it in a class, since it involves prototype syntax and I don’t know if that’s adviced in a class. (Isn’t there a include statement or can “import” also include non-classes?).