Skip to main content
Inspiring
July 3, 2008
Question

can you detect if listener is applied?

  • July 3, 2008
  • 7 replies
  • 518 views
I am writing a class and would like to have it remove a listener only if it is listening (hence created). I tired just removeEventListener(); but i get the error access of an undefined property - b/c it hasnt been created - yet.

This topic has been closed for replies.

7 replies

kglad
Community Expert
Community Expert
July 4, 2008
you're welcome.
_Vee_Author
Inspiring
July 4, 2008
Ok, i will. Thanks.
kglad
Community Expert
Community Expert
July 3, 2008
no. just use:

try {
//whatever <- this is the only line you need to customize
} catch(e:Error){
}
_Vee_Author
Inspiring
July 3, 2008
Great stuff guys. Thank you. That did it... I put the event type in as suggested.

As for try{}catch(){}, do youhave to speicfy the exact error?
kglad
Community Expert
Community Expert
July 3, 2008
p.s. for most compiler errors you can use try{}catch(){} to prevent the compiler from complaining.
Inspiring
July 3, 2008
Calling the removeEventListener() method on an instantiated object (EventDispatcher) that doesn't have that matching event listener already assigned to it won't do any harm. But obviously you can't call that method on an object (EventDispatcher) that's not been instantiated.

BTW, if you use hasEventListener(), you must supply the event type as an argument hasEventListener(MouseEvent.ROLL_OVER)

TS
July 3, 2008
try this:

if(aines.submit_btn.hasEventListener())
{
aines.submit_btn.removeEventListener(MouseEvent.ROLL_OVER, submitRollOver);
}