Mouse scroll wheel in flash not working in Chrome
Chrome’s latest update to version 21 introduced a new type of flash player using the PPAPI (pepper) plugin architecture.
I noticed that this version of flash started breaking mouse scroll wheel support for some flash content.
Which flash files break and which don’t depend on one thing; if you are using JavaScript to prevent the default behavior of the mouse scroll wheel or not.
The reason for preventing default mouse scroll wheel behavior is for when you don’t want the page to scroll when you scroll over the flash content.
To prevent that, developers write JavaScript code (or use libraries like SwfWheel.js) that add an event listener for the “mousewheel” or “DOMMouseScroll” event, and in the handler call “evt.preventDefault()” and/or “evt.returnValue = false” to cancel the scroll.
Therein lies the problem, the old NPAPI Flash Player would receive the mouse scroll event even if we prevented the default behavior. Maybe even incorrectly so, since the event was cancelled.
The new PPAPI Flash Player will not receive the event if the default is prevented.
If one were to remove the preventDefault() function, the Flash file would start working correctly again, but the whole page would again start scrolling, which is out of the question.
You will have to not only prevent the default scroll behavior, but also call an external interface function in your flash file to let it know when the user scrolls the mouse wheel.
In my case I was using SwfWheel and only needed a small modification to the library file: in the SWFWheel.getState() function add this code before the “if (br.mac)” line:
// The new pepper plugin requires chrome to always be hacked. if (br.chrome) { return STATE_HACKED; }
Tags: Chrome, mouse, NPAPI, pepper, PPAPI, preventDefault, returnValue, scroll, SwfWheel, wheel
August 17th, 2012 at 11:49
Thanks for the info and the bug fix.
Did you send a ticket on libspark.org ?
August 21st, 2012 at 19:17
I wanted to but their whole ticket system is in Japanese :/
August 28th, 2012 at 13:02
I modified the file exactly like you did, but I get “Uncaught Error: Error calling method on NPObject in SWFWheel.bind”. I only get this error message in Chrome, in another browsers the library works just fine. Could you please provide a workable demo implementation of a flash/flex project?
August 29th, 2012 at 09:04
@Sergiu: Try it with the debug flash player from http://www.adobe.com/support/flashplayer/downloads.html
It should give you a more descriptive error that your Flash file is most likely throwing.
August 29th, 2012 at 17:11
I immediately switched over to SWFWheel to solve this problem, applying your fix. Very useful, thanks.
Please note this issue arising from the same chromium pepper flash release, it’s related to default fonts in textfields. http://code.google.com/p/chromium/issues/detail?id=140415
August 30th, 2012 at 07:54
Turns out it was a silly error. My stage object was null. Great post!
September 10th, 2012 at 16:00
This must be why my MouseWheelTrap util doesn’t work in Chrome http://code.google.com/p/mousewheeltrap. It’s purpose was to easily prevent simultaneous Flash and browser scrolling, while your mouse is over Flash content.
Wish Adobe would fix this at source, since I can’t think of any use case where you’d want both things scrolling at once.
I’m no JavaScript expert, so would welcome help fixing the MouseWheelTrap utility.
October 2nd, 2012 at 05:45
I have a follow-up bug to report, also only occurring in Chrome. Scrolling usually works fine, unless you try to scroll when your cursor is over an empty area (ie. nothing rendered). When you put your cursor over a rendered object and scroll, it works again.
Any ideas?
October 8th, 2012 at 10:42
Have you got a working example of this to download and look at? Would be much appreciated. Thanks
October 11th, 2012 at 18:17
Sure @marx, here’s the class with the fix: http://pastebin.com/A2WCjvf5