Skip to main content
Inspiring
May 26, 2017
Question

Please help- How to use Mousewheel EventListener only over certain movieclips?

  • May 26, 2017
  • 1 reply
  • 1505 views

I'm using a code klad posted for html5 canvas with animate cc using the scroll wheel, to detect scroll up and scroll down to do different things for each one,

but the problem is its detecting the entire canvas.

Is there a way to make it so you can only scroll when the mouse is over certain movie clips with specific ID in html5 canvas?

So I can for example have more control on WHEN you can scroll and WHERE.

Then I can hide and show movieclips on the timeline and only when certain ones with certain ID is visible, and your mouse is over them, then do something different (like playing from  certain frames, depending if you scroll up or down)

It would be so amazing if someone could let me know if this is possible and how to go about it. Here is the current code he posted:

document.getElementById('canvas').addEventListener('mousewheel',f.bind(this));

document.getElementById('canvas').addEventListener('DOMMouseScroll',f.bind(this));

function f(e){

if (e.wheelDelta > 0||e.detail>0){

this.gotoAndPlay(2);

} else if(e.wheelDelta < 0||e.detail<0){

this.gotoAndPlay(10);

}

}

This topic has been closed for replies.

1 reply

Legend
May 26, 2017

Have you tried just adding the scroll event listeners to the movieclips instead of the entire canvas?

Inspiring
May 26, 2017

I tried changing this:

document.getElementById('canvas').addEventListener('mousewheel',f.bind(this));

document.getElementById('canvas').addEventListener('DOMMouseScroll',f.bind(this));

to this:

this.MovieClip1.addEventListener('mousewheel',f.bind(this));

this.MovieClip1.addEventListener('DOMMouseScroll',f.bind(this));

but scrolling no longer works and becomes broken.

What is the proper way to add the scroll event listeners to the movieclips?
I'd really like to be able to have the mousewheel listen only on certain frames too, but I'm not sure how to do that either.

Inspiring
May 27, 2017

The example code captures a reference to the movieclip that triggered the mouseover event, then attempts to control that same clip. I have no idea how you've structured your project and whether or not that is appropriate.


Here is a screenshot of my project structure, basically I have 1 movie clip where everything is happening in.

So when you click an arrow movieclip it moves the rectangle movieclip on the same timeline. Not a nested one. Just trying to find out how to hover over an arrow and mouse wheel up and down to go to a frame on the same timeline. All my actions are set on different frames to enable / disable clicking, so I thought the same could be applied for the mouse wheel. http://i.imgur.com/i4KwAUO.png

i4KwAUO.png