Question

I have a situation where i am trying to remove certain movie clips that do not have any instance name given to them , they are created dynamically , i can find the movieclips by using the below code :

for (var i:uint = 0; i <worldc1.numChildren; i++){

  trace (worldc1.getChildAt(i).name );

}

however as i know that some default instance name is assigned to each movie clip , that starts with word "instance" ...

How can i remove all such movie clips that have word "instance" in their name ...

Or best how i can remove a movieclips that has no instance name assigned to it and are dynamically created ....

I tried using the contains but its not working .....

Thanks in advance ...

Regards

Was it helpful?

Solution

Try using this function:

removeClipsWithNameContaining(worldc1, "instance");


function removeClipsWithNameContaining(target:DisplayObjectContainer, str:String):void {

    var clips:Array = [];

    for (var i:uint = 0; i < target.numChildren; i++){
        if(target.getChildAt(i).name.indexOf(str) != -1) clips.push(target.getChildAt(i));
    }

    var c:int = clips.length;       
    while(--c > -1) target.removeChild(clips.pop());

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top