简体   繁体   English

如何删除实例名称中包含特定单词的电影剪辑

[英]How to remove movieclips that contains specific word in instance name

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 " ... 但是据我所知,每个电影剪辑都分配了一些默认实例名称,该名称以单词“ instance ”开头...

How can i remove all such movie clips that have word " instance " in their name ... 如何删除名称中带有“ instance ”一词的所有此类影片剪辑...

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 问候

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM