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:
and, when they click the Chapter or Lesson MenuItem:
Code:
for each (var h in children){
mainMenu_mc.menuContainer_mc.removeChild(children[h]);
}
but I get:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/removeChild()
at vdmv8_fla::MainTimeline/menuClick()
?
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
for each (var h in children){
trace("var h "+h);
var h [object MenuItem]
Code:
mainMenu_mc.menuContainer_mc.removeChild(getChildByName(children[h]));
TypeError: Error #2007: Parameter name must be non-null.
at flash.display::DisplayObjectContainer/getChildByName()
at vdmv8_fla::MainTimeline/menuClick()
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
trace("children "+children.length);
//returns children 13
trace("children.toString() "+children.toString());
//returnschildren.toString() nI0,nI1,nI2,nI3,nI4,nI5,nI6,nI7,nI8,nI9,nI10,nI11,nI12
for each (var h in children){
trace("var h "+h);
//returns var h nI0
mainMenu_mc.menuContainer_mc.removeChild(getChildByName(children[h]));
}
TypeError: Error #2007: Parameter name must be non-null.
at flash.display:isplayObjectContainer/getChildByName()
at vdmv8_fla::MainTimeline/menuClick()
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.