I cannot seem to set and unset buttonMode and event listeners in a child movieclip that I have created dynamically within a holding movieclip.
Each child movieclip contains a number of images that I want to have the user click to open a larger image. As the user clicks a series of buttons the holding movieclip slides bringing the relevant sub movie clip slides into the centre of the screen which then becomes active.
All this works fine except that when I try to disable the buttonMode of those sub movieclips not in the centre I get errors.
I create the sub movieclips as follows:
my_mc = new MovieClip();
my_mc.x = my_x;
my_mc.y = 0;
holding_Mc.addChild(my_mc);
my_mc.name = my_mcName;
//my_mcName is a String and set earlier to "section_" + my_sectionNum
//my_sectionNum is a Number and set to earlier when a user presses one of 7 buttons (sections 1 - 7)
once the images have been loaded into the sub movieclip using XML I set the buttonMode of the sub movieclip to true and create an event listener
this.my_mc.buttonMode =true;
this.my_mc.addEventListener(MouseEvent.CLICK, onImageClick)
This all works fine. It is when I come to want to remove the event listener from a specific sub movieclip by using the movie clip name I set previously i.e my_mcName and re-add the event listener and buttonMode to one of the other sub movieclips.
This is the code I am using:
function onNav_btnClick(evt:MouseEvent):void{
holding_Mc.getChildByName(my_mcName).buttonMode = false;
holding_Mc.getChildByName(my_mcName).removeEventListener(MouseEvent.CLICK, onImageClick);
switch (evt.target.name){
case "open_nav_1_btn":
my_sectionNum = 1;
break;
case "open_nav_2_btn":
my_sectionNum = 2;
break;
// MORE SWITCH STATEMENTS
}
sectionLoad;
}
function sectionLoad(): void{
my_mcName = "section_" + my_sectionNum;
if (holding_Mc.getChildByName(my_mcName) != null) {
holding_Mc.getChildByName(my_mcName).buttonMode = true;
holding_Mc.getChildByName(my_mcName).addEventListener(MouseEvent.CLICK, onImageClick);
}
else{
//LOAD NEW SUB MOVIECLIP
}
}
I cannot seem to get this right. I suspect I am referencing the sub movieclip wrongly in some way. The sub movieclips are visible so I presume they are on the Display list.
It is funny that my if statement works correctly and references the correct sub movieclip.
Pulling hair out… please put me out of my misery.
Thx