0

I'm setting up an introduction to using Javascript in Adobe Animate HTML5 Canvas for a course I teach. Honestly I haven't done any work in that myself but I've done a bit of Actionscript gaming as well as some Javascript programming outside of Animate, so I'm not entirely clueless.

Part of the exercise is to have a button that opens a URL. It does, but it opens many tabs of it. I'm nto sure how to limit it so it only opens one tab of the URL.

Here's my code. Thanks for your help:

this.urlBtn.addEventListener("mousedown", openPage.bind(this));

function openPage(event) {
 window.open('http://www.cartoonthunder.net/', '_blank');
}
Rob Campbell
  • 63
  • 11

1 Answers1

1

mousedown fires while the mouse is down over the element, so it'll happen repeatedly.

Use click instead and it should only fire once.

samanime
  • 25,408
  • 15
  • 90
  • 139
  • click does the same thing. In Actionscript I'd use onRelease or something. – Rob Campbell Oct 03 '19 at 19:37
  • `click` should only fire once unless the mouse button is let go and then pressed again. Is the code sample missing something that might change how it works? You can also go very manual and verbose and combine `mousedown` and `mouseup` and track with a boolean, but that is overkill in JavaScript. – samanime Oct 03 '19 at 19:39
  • I agree with you. That is not what is happening, however. I'll keep trying and see what happens. I've also tried the boolean route and not gotten results. – Rob Campbell Oct 03 '19 at 20:09
  • Your point is confirmed (I already concurred, but searched more) in this post as well. Must be something at my end. https://stackoverflow.com/questions/46609874/adobe-animate-cc-html-5-open-url – Rob Campbell Oct 03 '19 at 20:42