Skip to main content
Known Participant
September 3, 2018
Answered

Unpredictable/Stubborn click event | HTML5 JS

  • September 3, 2018
  • 1 reply
  • 952 views

Hello

I have a click event on a MovieClip that only intermittently/arbitrarily responds. There is also a RollOver/Out event that responds alright, so I know the bounding box is working. I have put a rectangle at 0% Alpha inside the MovieClip just to cover more area. I have another click event in the beginning of the video (seen below) that works correctly 100% of the time. I put a small animation on my cursor each time I click in order to see where and when I am clicking.

here is the code relevant to the "info" MovieClip

this.info.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler(e) {

     if (e.currentTarget == this.info) {

          alert("clicked!");

     }

}

stage.enableMouseOver(3);

this.info.addEventListener("rollover", MouseEventHandler.bind(this));

this.info.addEventListener("rollout", MouseEventHandler.bind(this));

function MouseEventHandler(e) {

     e.currentTarget.play();

}

Is this a common problem with roll over/outs and click events? Any advice? Thanks

Max

This topic has been closed for replies.
Correct answer ClayUUID

The rollover was working perfectly consistently: It was detecting rollover when the mouse moved over visible pixels. The correct way to force a more contiguous rollover area is to assign a display object to the the movie clip's hitArea property, but yes, using a 1% alpha rect works too.

https://createjs.com/docs/easeljs/classes/MovieClip.html#property_hitArea

https://www.createjs.com/tutorials/Mouse%20Interaction/

1 reply

franciscog47374926
Known Participant
September 3, 2018

Hi,

Try checking if the object this.info already has en eventlistener before applying one to it.

Like this.

if(!this.info.hasEventListener("click"));

this.info.addEventListener("click", fl_MouseClickHandler.bind(this));

the rest of the code should be fine..

I had a similar problem and i thought it could help you. Strange buttons behavior

Regards,

pmwpmwAuthor
Known Participant
September 3, 2018

Hey There,

Thanks for your response. I tried your method, and it wasn't the solution for this particular problem, but I could see that being handy when I incorporate navigation into this canvas project.

I did find a solution however: I mentioned above that I put a rectangle inside the MovieClip at 0% Alpha to make a "hit box" of sorts. If I raise that Alpha up from 0% to 1%, the click event works perfectly and the Roll Over/Out events behave more consistently as well

In short, Animate CC doesn't respond to transparent objects. It needs at least a little bit of opacity to register events.

ClayUUIDCorrect answer
Legend
September 4, 2018

The rollover was working perfectly consistently: It was detecting rollover when the mouse moved over visible pixels. The correct way to force a more contiguous rollover area is to assign a display object to the the movie clip's hitArea property, but yes, using a 1% alpha rect works too.

https://createjs.com/docs/easeljs/classes/MovieClip.html#property_hitArea

https://www.createjs.com/tutorials/Mouse%20Interaction/