# Event target is not returning correctly?

**URL:** <https://forum.kirupa.com/t/event-target-is-not-returning-correctly/278882>\
**Category:** Uncategorized\
**Created:** [January 7, 2009, 12:03am UTC](https://forum.kirupa.com/t/event-target-is-not-returning-correctly/278882 "2009-01-07T00:03:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andysk8er](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@andysk8er](https://forum.kirupa.com/u/andysk8er)\
**Post date:** [January 7, 2009, 12:03am UTC](https://forum.kirupa.com/t/event-target-is-not-returning-correctly/278882/1 "2009-01-07T00:03:51Z")

</div>

Okay, I have a weird problem and I’m not sure if it is possible to do what I’m trying to do.

I have a navigation with 4 dropdown menus (with instance names mainNav1\_mc, mainNav2\_mc, etc). Inside those dropdown menus are buttons (with instance names nav1\_1, nav1\_2, etc…). The button behavior is controlled by a custom class called BasicButton that extends MovieClip. All of this works great.

The problem comes when I try to match the target of an event listener to the object it was added to… here’s the code (inside the Navigation class file):

this.mainNav1\_mc.nav1\_1.addEventListener(MouseEvent.CLICK, selectNav1\_1);  
trace(mainNav1\_mc.nav1\_1);

private function selectNav1\_1(evt:MouseEvent):void {  
trace(evt.target);  
if (evt.target == this.mainNav1\_mc.nav1\_1) {  
trace(“they are the same!”);  
}  
}

THIS DOESN"T WORK! The first trace returns [object Subnav0\_5]. Awesome. The second trace returns a generic [object MovieClip] instead of [object Subnav0\_5] and the third trace never fires!

Am I missing something? I’ve tried casting the target as a BasicButton, but it didn’t work. Anyone able to help with this?

BTW, in case you’re wondering why I would EVER want to do this, I am creating an extensible drop-down menu system which is created on the stage and then initialized in the code with a series of arrays. The code is generalized, so I will not need to touch the functionality, no matter how many menus there are or how many buttons are in each menu. I simply need to add them to the arrays.

Thanks,  
Andy
