Skip to main content
chrismay_at_delta6226261
Inspiring
March 20, 2018
Answered

Javascript - removeEventListener

  • March 20, 2018
  • 1 reply
  • 699 views

I am experiencing some issues with removeEventListener. As far as I can tell, this does not actually end the event listener.

My code:

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",function(){runTimer(z, x);},"cpInfoCurrentFrame");

and then later on I call:

window.cpAPIEventEmitter.removeEventListener("CPAPI_VARIABLEVALUECHANGED",function(){doRemove();},"cpInfoCurrentFrame");

If I call the addEventListener multiple times (on enter of every slide), I get multiple instances of the function runTimer() running.

When i call the removeEventListener, the function doRemove() is never called.

I am on a Mac and running Captivate 2017 10.0.0.226

Thanks!

This topic has been closed for replies.
Correct answer

In JavaScript you cannot remove and event listener that contains an anonymous function.

You would need to use:

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",someFunction,"cpInfoCurrentFrame");

1 reply

Correct answer
March 20, 2018

In JavaScript you cannot remove and event listener that contains an anonymous function.

You would need to use:

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",someFunction,"cpInfoCurrentFrame");

chrismay_at_delta6226261
Inspiring
March 20, 2018

AH HA!

Thanks, that did the trick.

BTW - this info is out of date:

Learn about the Common JavaScript interface for Adobe Captivate

My code now looks like:

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",runTimer,"cpInfoCurrentFrame");

and

window.cpAPIEventEmitter.removeEventListener("CPAPI_VARIABLEVALUECHANGED",doRemove2,"cpInfoCurrentFrame");