Determine object triggering an event?

Hello!

I am having an issue where I am unable to make my script determine which button in my menu is triggering the event (MOUSE_UP). I came pretty close to success by finding the “target” property but its not reliable if I have clips within my button.

If anyone could give me the solution to that problem it would be nice =) Looked around and couldn’t find an answer. Thank you!

The animation is not done yet also.


package {
    import flash.display.*;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.events.MouseEvent;
    import flash.utils.Timer;
    import flash.text.TextField;
    import flash.text.TextFormat;

    public class createMenus extends Sprite {
        
        
        var i:Number;
        var menuArray:Array = new Array("Menu 1", "Menu 2", "Menu 3", "Menu 4", "Menu 5")
        var nbMenus:Number = menuArray.length;
        static var clip:Number = 1;
        
        public function createMenus() {

            for(i=1;i<=nbMenus;i++)
            {
                /*CREATE MENU*/
                var mc_menu:MovieClip = new MovieClip();
                mc_menu.graphics.beginFill(0x000000);
                mc_menu.graphics.drawRect(0,i*20,100,15);
                mc_menu.graphics.endFill();
                mc_menu.name = "menu"+i;

                mc_menu.addEventListener(MouseEvent.MOUSE_UP,clickMenu)
                
                function clickMenu(clicked:Event) {
                    trace(clicked.target.name);
                    /*Bug is here, if I click on the button it returns me menu1 to 5 depending on which I click (Thats what its supposed to do.) But if I happen to click on the text within that button it returns me the name of the text instance, example "instance9")*/

                }

                /*TEXT FORMAT*/
                var myFormat:TextFormat = new TextFormat();
                myFormat.font = "Verdana";
                
                
                /*TEXT FIELD*/
                var txtField:TextField = new TextField();
                
                txtField.textColor = 0xffffff
                txtField.text = menuArray[i-1];
                txtField.selectable = false;
                txtField.setTextFormat(myFormat);

                txtField.width = txtField.text.length*9;
                
                txtField.x = mc_menu.x
                txtField.x += (mc_menu.width/2) - txtField.width/2;
                txtField.y = (i*20) - 2;
                
                
                /*EVENT*/
                mc_menu.timer = new Timer(500,1);
                mc_menu.timer.addEventListener(TimerEvent.TIMER,onTick);
                mc_menu.timer.start();

                addChild(mc_menu);
                mc_menu.addChild(txtField);
            }
        }
        
        
        public function onTick(myEvent:Event) {
            
            getChildByName("menu"+clip).addEventListener(Event.ENTER_FRAME, moveMenu);
            clip++;
        }
        
        public function moveMenu(myEvent:Event) {
            var targetX:Number = 200;
            var speed:Number = 0.1;
            
            
                for(i=1;i<=nbMenus;i++)
                {
                    //trace(getChildByName("menu"+i).x)
                    getChildByName("menu"+i).x += (targetX - getChildByName("menu"+i).x)*speed;
                }
        }
    }
}