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);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *