Skip to main content
Inspiring
Jun 16, 2011 4:08 AM UTC
Answered

Check if eventListener exist?

How do I check if an eventListener exist? If it exist, I want to remove it with removeEventListener.

addEventListener(MouseEvent.MOUSE_DOWN, btn_Click3)

addEventListener(MouseEvent.MOUSE_DOWN, btn_Click2)

addEventListener(MouseEvent.MOUSE_DOWN, btn_Click)

This topic is closed to new replies. Start a new post to keep the conversation going.
kglad
kgladCorrect answer
Community Expert
Jun 16, 2011 2:25 PM UTC

use the code i showed,

hasEventListener()

in any frame where the object exists.

7 replies

kglad
Community Expert
Community Expert
Jun 16, 2011 4:17 AM UTC

use the hasEventListener() method:

if(btn_3.hasEventListener(MouseEvent.MOUSE_DOWN){

btn_3.removeEventListener(MouseEvent.MOUSE_DOWN,btn_Click3);

}

Translate
ZainuuAuthor
Inspiring
Jun 16, 2011 4:26 AM UTC

Hi, what if btn_3 is in another frame, how do I check it?

otherwise I will get error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
Translate
kglad
Community Expert
Community Expert
Jun 16, 2011 4:44 AM UTC

if an object doesn't exist, you can't reference it with actionscript.  if it exists elsewhere (like frame 3), you can reference it elsewhere (like frame 3).

Translate