|
-
[RESOLVED] addEventListener problem
Hi all,
I have a problem with the event listener on a movieclip that has a dynamic text field. The problem is that in my event listener handler method:
Code:
//this works fine
this[section]["subsection"+i].addEventListener(MouseEvent.MOUSE_UP,processSubSectionClick);
...
...
//this trace gives the instance id of the dynamic text
function processSubSectionClick(evt:MouseEvent):void{
trace("button clicked = "+evt.target.name)
}
The true problem is that if I click on the button where the dynamic text is, I get the instance id of the dynamic text, which is not what I want. If i click on the button but not on the text, I get the correct result. Its if as though the text has precedence on the mouse event listener.
Code:
Example output:
button clicked = dt_subsectionTitle //wrong: clicked on Dynamic Text
button clicked = subsection0 //correct mc instance id: clicked on button image away from text
Has anybody seen this before and is there a solution?
Regards
Jason
-
You are using the 'MouseEvent.MOUSE_UP'. If you are trying to detect clicks you should use the 'MouseEvent.CLICK'.
-
Use currentTarget rather than target to get the instance to which the listener was added.
-
Thank you for your quick response
I have just changed the MouseEvent.CLICK but I still get the same [incorrect] behaviour
-
 Originally Posted by 5TonsOfFlax
Use currentTarget rather than target to get the instance to which the listener was added.
trace("button clicked = "+evt.currentTarget.name)
This solves the problem. Thanks a lot!!
-
The behavior is not incorrect, your code is. The text is the thing you clicked on, so it is the correct target of the event. You need to use currentTarget to get the object currently processing the event.
Whoops. Posted while you were writing. Oh well. Glad it worked out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|