Getting event targets on buttons

Hi folks,

I’ve got brainache again… I’ve got a set of 3 buttons repeated in 9 MCs (i.e. 27 buttons in total) which when clicked remove the other MCs from the stage then need to change their mouseDown event handler to do something different. The button that was clicked however remains disabled until one of it’s siblings is clicked.

I have got this to work of a fashion but I know it’s not great… I think I’d really need to know which button was pressed and only add the new event handlers its siblings. Plus my approach isn’t extensible - because the index values might change in the future & it would break…


        private function mouseDownHandler(event:MouseEvent):void 
        {
            // disable all the other MCs using another class - this works OK
            var showHide:MovieControl = new MovieControl();
            showHide.ShowThisMCOnly(event, MCArray);
            
            // starts getting daft here
            var thisBtn = event.target;
            var thisParent = thisBtn.parent;
            var thisGParent = thisParent.parent;
            
            var child_2 = thisGParent.getChildAt(2);
            var child_3 = thisGParent.getChildAt(3);
            var child_4 = thisGParent.getChildAt(4);
            
            // remove all the existing event handlers
            child_2.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            child_3.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            child_4.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            
            // add some new ones
            child_2.addEventListener(MouseEvent.MOUSE_DOWN, newMouseDownHandler);
            child_3.addEventListener(MouseEvent.MOUSE_DOWN, newMouseDownHandler);
            child_4.addEventListener(MouseEvent.MOUSE_DOWN, newMouseDownHandler);

            // disable the current button
            event.target.enabled = false;
            event.target.alpha = 0.5;
            
            // this always returned "target not found"            
            if (thisBtn == child_2) 
            {
                trace ("button 1");
            } else if (thisBtn == child_3) 
            {
                trace ("button 2");
            } else if (thisBtn == child_4) 
            {
                trace ("button 3");
            } else {
                trace ("target not found");
            }
       }

Thanks for taking a look, can you enlighten me please?

Ben