Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript - removeEventListener

Contributor ,
Mar 20, 2018 Mar 20, 2018

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!

613
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Mar 20, 2018 Mar 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");

Translate
Guest
Mar 20, 2018 Mar 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");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 20, 2018 Mar 20, 2018
LATEST

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");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources