This is a recursive algorithm you can use to remove everything nested inside a MovieClip hierarchy.
It's all very self explanatory. The 'removeEverything' function takes a MovieClip and for every child which is also MovieClip, calls itself, passing the child as the argument. The 'removeAllChildren' function simply removes every child of its argument MovieClip. This gets called only when every call to 'removeEverything' has returned.
//Remove Everything
function removeEverything(mc:MovieClip)
{
for(var i:int = mc.numChildren-1; i >=0; i--)
{
if(getClass(mc.getChildAt(i)) == MovieClip)
{
removeEverything(MovieClip(mc.getChildAt(i)));
}
}
removeAllChildren(mc);
}
//Remove All Children
function removeAllChildren(mc:MovieClip)
{
while(mc.numChildren)
{
mc.removeChild(MovieClip(mc).getChildAt(0));
}
}
//Get Class
function getClass(obj:Object):Class
{
return Class(getDefinitionByName(getQualifiedClassName(obj)));
}