Referencing dynamicaly created child movie clip

I have used AS3 in frame 1 of the timeline to create a holding MC ‘opening_Mc’ into which 7 sub MCs are loaded when the user presses each of 7 buttons. When each of the sub MCs loads it is populated with images using XML.

When the button is presses ‘opening_Mc’ slides to reveal the position of the respective sub MC.

I dynamically create each sub MC and reset it’s name to the respective section name… so if the user presses button 1 the sub MC will end up with the name ‘section_1’.

The button mode of the sub MC is set to ‘true’ so that a larger image can be loaded when the user clicks on each of the images.

Thanks to help from this forum all this all works.

The problem I have is that if the user presses a button after the initial load of the images I want the resepective sub MC to move to the centre and become active.

Here is the section of the code:


function onNav_btnClick(evt:MouseEvent):void{
     
    
    this.my_mc.removeEventListener(MouseEvent.CLICK, onImageClick);
    my_mc.buttonMode = false;
    //opening_Mc.buttonMode = false;

     switch (evt.target.name){
        case "open_nav_1_btn":
            tween_finish_opener = 3600 ;
            tween_finish_buttons = 0;
            my_sectionNum = 1;
            my_x = -2700;
            
            break;
        case "open_nav_2_btn":
            tween_finish_opener = 2700 ;
            tween_finish_buttons = 129;
            my_sectionNum = 2;
            my_x = -1800;
            
            break;
        case "open_nav_3_btn":
            tween_finish_opener = 1800 ;
            tween_finish_buttons = 258;
            my_sectionNum = 3;
            my_x = -900;
            
            break;
         case "open_nav_4_btn":
            tween_finish_opener = 900;
            tween_finish_buttons = 386 ;
            my_sectionNum = 4;
            my_x = 0;
            
            trace(my_sectionNum);
            
            break;
        case "open_nav_5_btn":
            tween_finish_opener = 0;
            tween_finish_buttons = 514;
            my_sectionNum = 5;
            my_x = 900;
            
            break;
        case "open_nav_6_btn":
            tween_finish_opener = -900 ;
            tween_finish_buttons = 642;
            my_sectionNum = 6;
            my_x = 1800;
            
            break;
        case "open_nav_7_btn":
            tween_finish_opener = -1800;
            tween_finish_buttons = 771;
            my_sectionNum = 7;
            my_x = 2700;
            
            break;
     }
        
        TweenLite.to(nav_but_Mc.select_box, 1, {x:tween_finish_buttons});
        TweenLite.to(opening_Mc, 1, {x:tween_finish_opener, onComplete:sectionLoad});
    
}

function sectionLoad(): void{
    
    if (opening_Mc.getChildByName("section_" + my_sectionNum) == null) {

    var my_thumb_x:Number;
    var my_thumb_y:Number;
    
    var my_section_total:Number;

    var myXMLLoader:URLLoader = new URLLoader();
        myXMLLoader.load(new URLRequest("section" + my_sectionNum +".xml"));
        myXMLLoader.addEventListener(Event.COMPLETE, processXML);
    }
    else{ 
    
// THESE IS WHERE THE PROBLEM IS
    
    this.opening_Mc["section_" + my_sectionNum].buttonMode = true;
    this.opening_Mc["section_" + my_sectionNum].addEventListener(MouseEvent.CLICK, onImageClick);
    
    }
}

function processXML (e:Event):void{
    
    var myXML:XML = new XML(e.target.data);

    this["my_images" + my_sectionNum] = myXML.image;
    my_section_total = this["my_images" + my_sectionNum].length();
    
    trace(my_images);
    
    createContainer();
    callThumbs();
    
    this.my_mc.buttonMode =true;
    this.my_mc.addEventListener(MouseEvent.CLICK, onImageClick);
    
}

function createContainer():void {
    
     my_mc = new MovieClip();
    my_mc.x = my_x;
    my_mc.y = 0;
    opening_Mc.addChild(my_mc);

//THIS IS WHERE I RENAME MY_MC

    my_mc.name = "section_" + my_sectionNum;
}

function callThumbs():void{
    for (var i:Number = 0; i < my_section_total; i++){
    var thumb_url = this["my_images" + my_sectionNum]*.small_url;
    
    var thumb_loader = new Loader();
    thumb_loader.load(new URLRequest(thumb_url));
    thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);

    thumb_loader.name = i;

    thumb_loader.x = this["my_images" + my_sectionNum]*.xpos;
    thumb_loader.y = this["my_images" + my_sectionNum]*.ypos;

    }
}

function thumbLoaded(e:Event):void{

    var my_thumb:Loader = Loader(e.target.loader);
    this.my_mc.addChild(my_thumb);
}




I think I know what the problem is. I believe it is something to do with how I am renaming the MC ‘my_mc’ when I create the sub MCs and how I then reference these sub MCs when I want to make them active.

I rename using:

my_mc.name = “section_” + my_sectionNum;

I reference the sub MCs using:

this.opening_Mc[“section_” + my_sectionNum].buttonMode = true;
this.opening_Mc[“section_” + my_sectionNum].addEventListener(MouseEvent.CLICK, onImageClick);

What am I doing wrong.

Pulling my hair out

All help most gratefully received.