# MX: listener trips multiple times

**URL:** <https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137>\
**Category:** flash\
**Created:** [June 26, 2003, 1:11pm UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137 "2003-06-26T13:11:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lowprofile](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@lowprofile](https://forum.kirupa.com/u/lowprofile)\
**Post date:** [June 26, 2003, 1:11pm UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137/1 "2003-06-26T13:11:50Z")

</div>

Hi,

I finally found the problem with this part… I have a listener on the mouse for button up. However, it trigger from 1 - 4 times !!! for one event?

What is with that? Is there a way to avoid this?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 1:19pm UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137/2 "2003-06-26T13:19:39Z")

</div>

some code would help

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 1:38pm UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137/3 "2003-06-26T13:38:37Z")

</div>

myListener = new Object();  
myListener.onMouseUp = function(){  
if ( (this.button4.hitTest( \_root.\_xmouse, root.\_ymouse, false))  
|| (dont\_close==true) ){  
//Mouse is over the menu part don’t close it  
}  
else{  
close\_menu();  
}  
dont\_close = false;  
}  
Mouse.addListener(myListener);

Ignore the hitTest - that doesn’t work either!!! It works for a movie clip but not a button??? However, Flash says it should work for buttons too…

dont\_close gets set if the button is pressed because I have to try something else other than this hitTest since that doesn’t work.

I put in traces and found that it works fine and only exectues once if I start it and just press that button.  
Then once you try another button, you find that this button never works again and you can see the listener is triggering several times…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 1:43pm UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137/4 "2003-06-26T13:43:05Z")

</div>

Figured it out…

its ok…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 1:46pm UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137/5 "2003-06-26T13:46:12Z")

</div>

But I still don’t know what is up with the hitTest…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 1:54pm UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137/6 "2003-06-26T13:54:00Z")

</div>

```auto
if (button4.hitTest(_root._xmouse, _root._ymouse, false) || dont_close) {

```

??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 27, 2003, 11:47am UTC](https://forum.kirupa.com/t/mx-listener-trips-multiple-times/24137/7 "2003-06-27T11:47:53Z")

</div>

Is there a short cut to label code that is only to execute once?

It was that sometimes the movie might loop and it causes another mouse listener to be created each time so you start with one… two… three … etc.
