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: , , , , , , , , ,

10 Responses to “Mouse scroll wheel in flash not working in Chrome”

  1. menorki Says:

    Thanks for the info and the bug fix.

    Did you send a ticket on libspark.org ?

  2. Flassari Says:

    I wanted to but their whole ticket system is in Japanese :/

  3. Sergiu Says:

    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?

  4. Flassari Says:

    @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.

  5. Erik Westington Says:

    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

  6. Sergiu Says:

    Turns out it was a silly error. My stage object was null. Great post!

  7. Liam O'Donnell Says:

    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.

  8. Erik Westington Says:

    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?

  9. marx Says:

    Have you got a working example of this to download and look at? Would be much appreciated. Thanks

  10. Flassari Says:

    Sure @marx, here’s the class with the fix: http://pastebin.com/A2WCjvf5

Leave a Reply