Copy link to clipboard
Copied
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!
1 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");

Copy link to clipboard
Copied
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");
Copy link to clipboard
Copied
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");

