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

[canvas/js] click works, mouseup doesn't — anyone have any idea why?

Engaged ,
Nov 17, 2016 Nov 17, 2016

So I've been busy recreating my AS3 package for JS and I hit dials. My dial is set up where click-and-hold causes it to keep spinning. Normally I would listen for mouseout and mouseup to stop it spinning, but in JS this doesn't seem to be working. Instead I have to listen for click to get it to stop.

So, this code works, but I am curious as to *why* it works when mouseup should too?

Thanks in advance,
Eric.

PS: Not including all the code, for brevity, but here's the relevant bits. Also, I'm tracking 3 different button timers because the dial speeds up if you hold it down long enough, and there seems to be no way to change the timer delay interval like there is in AS3.

   // MouseEvent Constants

    this.MOUSE_CLICK = "click";

    this.MOUSE_DOWN = "mousedown";

    this.MOUSE_UP = "mouseup";

    this.MOUSE_OUT = "mouseout";

    this.addDialListeners = function(dial) {

        console.log("Dial",dial.getName());

        dial.btnCw.addEventListener(self.MOUSE_DOWN, self.autoInc);

      //dial.btnCw.addEventListener(self.MOUSE_UP, self.stopChange); // DOES NOT WORK SO USE CLICK INSTEAD?!

        dial.btnCw.addEventListener(self.MOUSE_CLICK, self.stopChange);

        dial.btnCw.addEventListener(self.MOUSE_OUT, self.stopChange);

        dial.btnCcw.addEventListener(self.MOUSE_DOWN, self.autoDec);

      //dial.btnCcw.addEventListener(self.MOUSE_UP, self.stopChange); // DOES NOT WORK SO USE CLICK INSTEAD?!

       dial.btnCw.addEventListener(self.MOUSE_CLICK, self.stopChange);

        dial.btnCcw.addEventListener(self.MOUSE_OUT, self.stopChange);

        dial.btnCcw.addEventListener(self.MOUSE_OUT, self.stopChange);

        self.disableControlNonHotSpots(dial);

    };

    this.autoInc = function(e) {

        self.currentDialEvent = e;

        self.dialUp(e);

        self.btnDownRepeat1 = setInterval(self.doBtnDownRepeats, self.delaySpeed1);

        console.log("AUTINC", self.btnDownRepeat1);

    };

    this.autoDec = function(e) {

        self.currentDialEvent = e;

        self.dialDn(e);

        self.btnDownRepeat1 = setInterval(self.doBtnDownRepeats, self.delaySpeed1);

        console.log("AUTODEC", self.btnDownRepeat1);

    };

    // Stop the timer on MOUSE_UP or MOUSE_OUT.

    this.stopChange = function(e) {

        console.log("STOP THE DIAL", self.btnDownRepeat, e.type);

        clearInterval(self.btnDownRepeat1);

        clearInterval(self.btnDownRepeat2);

        clearInterval(self.btnDownRepeat3);

        self.btnDownRepeat1 = -1; // Timer event tracker 1

        self.btnDownRepeat2 = -1; // Timer event tracker 2

        self.btnDownRepeat3 = -1; // Timer event tracker 3

        self.currentRepeatCount = 0;

    };

3.0K
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

Community Expert , Nov 17, 2016 Nov 17, 2016

i don't think there is a mouseup.  try pressup.

Translate
Community Expert ,
Nov 17, 2016 Nov 17, 2016

i don't think there is a mouseup.  try pressup.

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
Engaged ,
Nov 17, 2016 Nov 17, 2016

I think you're right. Just tested and it works now. Which KILLS ME!

Because my source for event names was the freaking Mozilla guide. They call out mouseup and have absolutely zero mention of pressup, lol. 😕

Event reference | MDN

At any rate, thanks for clearing that up, man!

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
Community Expert ,
Nov 17, 2016 Nov 17, 2016

you're welcome.

canvas uses easeljs, EaselJS v0.8.2 API Documentation : EaselJS

you can also use vanilla javascript, but then you run into all the usual problems with javascript: different browser/versions interpret it differently.  using a library like jquery helps remove a lot of the browser-to-browser variability.

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
Engaged ,
Nov 17, 2016 Nov 17, 2016

Yeah, I guess the full impact of that hadn't hit me. That is, hadn't realized they were overriding some basic functionalities like mouseup.

I just read about it and pressup is cool because it tracks the mouse up event even if it happens outside the object that started the event. So I can stop tracking mouseout altogether. Just wish I had figured this all out a weeka go, lol…

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
LEGEND ,
Nov 17, 2016 Nov 17, 2016
LATEST

heavyboots wrote:

Yeah, I guess the full impact of that hadn't hit me. That is, hadn't realized they were overriding some basic functionalities like mouseup.

CreateJS isn't overriding anything, it's implementing all those mouse events from scratch. Without the library the only mouse events you'd have would be the ones from the canvas element as a whole. All the objects drawn on the canvas don't actually exist as far as the browser DOM is concerned. That's why CreateJS has to simulate them.

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
LEGEND ,
Nov 17, 2016 Nov 17, 2016

There is a click event, which is what you would use for knowing that a user had clicked on a button. pressup is more for if they released after some time, and not necessarily on the original target.

Here's more information about the mouse events:

EaselJS Tutorial: Mouse Interaction

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
Engaged ,
Nov 17, 2016 Nov 17, 2016

Thanks, Colin! Yeah, I had gotten there by googling pressup after kglad mentioned it. Was mostly using resources on Mozilla's JS site before that, but I'll have to wade through the CreateJS stuff first now, I guess!

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