2011-11-14 57 views
0

我正在嘗試清理添加到MovieClip中的某些類,但似乎無法將MovieClip(Class)設置爲null。什麼是正確的方法來做到這一點?清理MovieClip中的嵌套動態影片剪輯(Class)

private var mcHolder:MovieClip = new MovieClip() 
    private var mcClass:MovieClip 

    private function someFunction():void 
    { 
     mcClass = new SomeClass() 
     mcHolder.addChild(mcClass) 
    } 

    private function clean():void 
    { 
     i = mcHolder.numChildren 
     if (i > 0) 
     { 
      while (i--) 
      { 
       MovieClip(mcHolder.getChildAt(i)).clean() 
       **MovieClip(mcHolder.getChildAt(i)) = null** 
       mcHolder.removeChild(MovieClip(mcHolder.getChildAt(i))) 
      } 
     } 
    } 

回答

0

只需使用removeChildAt()方法刪除子影片剪輯,並且不要手動設置任何空值。

private function clean():void 
    { 
     while (mcHolder.numChildren > 0) 
     { 
      mcHolder.removeChildAt(0); 
     } 
    }