Add Filters to Display Objects

Flash’s built-in filters (eg. blur/drop shadow) can be applied to display objects and bitmaps, though frankly it feels much more straightforward when you’re applying them to a display object instead of a bitmap. But I haven’t done anything with bitmaps yet … so …

All the filters are part of the flash.filters.* class.

// must import above the class definition
import flash.filters.DropShadowFilter;
// -- [..]

var myClip:MovieClip = new MovieClip();
var shadowFilter:DropShadowFilter = new DropShadowFilter(); // takes a lot of arguments ...
myClip.filters = [shadowFilter]; // filters is an instance variable from the DisplayObject class -- 'tis an Array

// if this was a bitmap (as opposed to a DisplayObject) we'd need to do applyFilter() or something

Sifting Through the Display List to Delete Things

Hah, it’s a pretty specific case … but this checks the last item of the display list and removes it if it partially matches (indexOf) the name on the display list item. This requires that the display list item to be given a name.

var myClip:MovieClip = new MovieClip();
myClip.name = "thenameofit";

if( getChildAt(numChildren-1).name.indexOf("thenameofit") > -1 ){
    removeChildAt(numChildren-1)
}

Yeah. Heh. So I’m keeping this code around, why? It could be used in the program I’m writing now, but it’s not nearly flexible enough as this, which loops through the display list and removes any child with containing a partially match of “deleteme”. Much more flexible, but also more intensive in a complex movie?

for( var i:int=0; i < this.numChildren; i++ ){
    if( getChildAt(i).name.indexOf('deleteme') > -1 ){
        removeChildAt(i);
    }
}