规格:
FindMovieClip(StartToSearchMovie:MovieClip, WantToSearchMovieName:String)
StartToSearchMovie:从哪个影片实体开始找起,通常是 _root。
WantToSearchMovieName:你想寻找影片实体的名称。
用途:
使用名称搜寻影片实体。
使用名称来搜寻影片实体有个好处,就是当你想要 reference 影片实体时不用去指明阶层关系。
实例:
var?tgm:MovieClip?=?FindMovieClip(_root,?"MyMovie");?
源码:
代码:???
?function?FindMovieClip?(oStart?:?MovieClip,?sName?:?String,?tmpArray?:?Array)?:?MovieClip?
???{?
??????var?rtMovie?:?MovieClip?=?null;?
??????var?tmpMovie?:?MovieClip?=?null;?
??????var?mclips;?
??????if?(tmpArray?==?undefined)?tmpArray?=?new?Array?();?
??????for?(mclips?in?oStart)?
??????{?
?????????var?oMovie_mc?=?oStart?[mclips];?
?????????if?(oMovie_mc?instanceof?MovieClip)?
?????????{?
????????????tmpMovie?=?IsInArray?(oMovie_mc._name,?tmpArray);?
????????????if?(tmpMovie?==?null)?
????????????{?
???????????????tmpArray.push?(oMovie_mc);?
???????????????if?(oMovie_mc._name?==?sName)?
???????????????{?
??????????????????rtMovie?=?oMovie_mc;?
??????????????????break;?
???????????????}?else?
???????????????{?
??????????????????rtMovie?=?FindMovieClip?(oMovie_mc,?sName,?tmpArray);?
??????????????????if?(rtMovie?!=?null)?break;?
???????????????}?
????????????}?
?????????}?
??????}?
??????return?rtMovie;?
???}?
???function?IsInArray?(movieName?:?String,?tmpArray?:?Array)?:?MovieClip?
???{?
??????var?i?:?Number?=?0;?
??????var?tmpMovie?:?MovieClip?=?null;?
??????var?rtMovie?:?MovieClip?=?null;?
??????for?(i?=?0;?i?<?tmpArray.length;?i?++)?
??????{?
?????????tmpMovie?=?tmpArray?[i];?
?????????if?(tmpMovie._name?==?movieName)?rtMovie?=?tmpMovie;?
??????}?
??????return?rtMovie;?
???}?