I'm using a class to dynamically populate menu items based on arrays. The menu has to allow individual chapters and lessons to expand/contract to display the slides within.

I'm trying to set it up so that when the user hits the Chapter or Lesson item, it rebuilds the menu with the appropriate Chapter/Lesson expanded. I've got that part working, but I need to remove the elements that were previously added using addChild, but I'm not sure how to clear all the elements from an object??

Here's the key parts of the code that builds the menu:

Code:
function InitMenu() {
	for each (var i in chpArray) {
                var newInstance:MenuItem=new MenuItem(i);
		newInstance.y=lastY;

		mainMenu_mc.menuContainer_mc.addChild(newInstance);
...
...and then it loops through the lessons and slides, creating newInstance2 and newInstance3 if that particular chapter/lesson is "tagged" to be expanded.

So, when the user clicks a different chapter/lesson, I need to remove all the items from the menu and rebuild it based on the new selected chapter/lesson...

I tried putting the following in when the user click a menu item, but I don't know how to reference the children I want to remove:

Code:
mainMenu_mc.menuContainer_mc.removeChild(newInstance);
but that gives an error since newInstance is created in the other function...

Thanks!!