规格:
FindMovieClip(StartToSearchMovie:MovieClip, WantToSearchMovieName:String)
StartToSearchMovie:从哪个影片实体开始找起,通常是 _root。
WantToSearchMovieName:你想寻找影片实体的名称。
用途:
使用名称搜寻影片实体。
使用名称来搜寻影片实体有个好处,就是当你想要 reference 影片实体时不用去指明阶层关系。
实例:
vartgm:MovieClip=FindMovieClip(_root,"MyMovie");
源码:
代码:
functionFindMovieClip(oStart:MovieClip,sName:String,tmpArray:Array):MovieClip
{
varrtMovie:MovieClip=null;
vartmpMovie:MovieClip=null;
varmclips;
if(tmpArray==undefined)tmpArray=newArray();
for(mclipsinoStart)
{
varoMovie_mc=oStart[mclips];
if(oMovie_mcinstanceofMovieClip)
{
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;
}
}
}
}
returnrtMovie;
}
functionIsInArray(movieName:String,tmpArray:Array):MovieClip
{
vari:Number=0;
vartmpMovie:MovieClip=null;
varrtMovie:MovieClip=null;
for(i=0;i<tmpArray.length;i++)
{
tmpMovie=tmpArray[i];
if(tmpMovie._name==movieName)rtMovie=tmpMovie;
}
returnrtMovie;
}