Shawnblais.com v2

The Lab

Firefox 3 Scroll Wheel Fix

with 11 comments

There a bug in Firefox 3 which causes the MOUSE_WHEEL event to always fire twice, no matter what.

Here’s the official bug report: http://bugs.adobe.com/jira/browse/FP-347

For a site like mine this is a major usability issue, here’s a fix (thanks to Martin Fernandez Lombana for the idea):

protected function addMouseWheelListener() {
	this.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseScroll);
}

private function onMouseScroll(event:MouseEvent){

   //Scroll logic...

   //Remove listener and add it back in 1 millisecond
   this.removeEventListener(MouseEvent.MOUSE_WHEEL, onMouseScroll);
   setTimeout(addMouseWheelListener, 1);
}

You will have to import the setTimeout function for this (flash.utils.setTimeout), or use a Timer. I’m not a big fan of the Timer class as of now, Timer still suffers from the same inconsistencies as the setTimeout fxn (framerate dependant, not a true timer) so I’m not sure what the benefit is…

On another note, I’m starting to get pretty sick of these Browser/OS specific bugs these days! One of Flash’s biggest strengths has always been platform independancy and that really seems to be taking a nosedive lately. For my site alone I had to implement 3 hacks:

  • Hack 1 – Use MacMouseWheel Javascript function to enable scroll wheel support. (Mac)
    Admittedly, a very clean implementation is already out there, but the entire concept of using Javascript to make ExternalInterface calls, just to enable a core function of the player seems totally Ghetto to me…
     
  • Hack 2 – Implement custom logic to detect invalid mouseY and mouseX values when cursor is off the stage. (Mac)
    Another strange one, on Mac you will get values like -1000000000 when off the stage…bizzaro
     
  • Hack 3 – Fix Mouse Scroll problem for Firefox (Windows)

It’s a bit worriesome, where will we be in 3 – 4 years if this trend continues to grow as it is now?

Written by Shawn

August 20th, 2009 at 10:01 am

Posted in Uncategorized

11 Responses to 'Firefox 3 Scroll Wheel Fix'

Subscribe to comments with RSS or TrackBack to 'Firefox 3 Scroll Wheel Fix'.

  1. [...] Click here for more info… [...]

  2. If you are not using MacWheel (js) then it is clear your site wont have wheel support on mac so in the end you will HAVE to use it.

    jsaade

    29 Sep 09 at 2:07 am

  3. Ya you do have to use it, and in itself it’s not a big deal.

    My bigger problem is with this trend of browser/os specific bugs, as flash gets more and more complex these issues are going to be harder to find and harder to test, wasting everyone’s time…

    admin

    29 Sep 09 at 6:41 am

  4. Firefox send the second WM_MOUSEWHEEL after it flows back from the falsh plugin so this will also work around the problem.

    private function onMouseScroll(event:MouseEvent){

    //Scroll logic…

    //stop the propagation
    event.stopPropagation();
    }

    Be careful not to prevent other mouse wheel listener from receiving the event.

    Gauthier

    17 Nov 09 at 9:48 am

  5. Ahh, awesome tip! Thanks.

    admin

    17 Nov 09 at 11:38 am

  6. The stopPropogation snippet doesn’t work for me, the even still fires twice in FF:

    private var numCalls:int = 0;
    public function holdContMain_OnMouseWheel(e:MouseEvent):void
    {
    numCalls++;
    lblHold.text += numCalls.toString() + ” “;
    e.stopPropagation();
    }

    The lable shows 12 34 56 etc.

    avejidah

    20 Nov 09 at 12:35 pm

  7. Has anyone gotten the stopPropagation to work? It doesn’t work for me… I tried putting it at the start of the scrollHandler and at the end of it (after my scrolling code).

    I’d prefer to not put a timer in if there’s another solution. Anyone have any ideas?

    Thanks!

    blindgoat

    20 Nov 09 at 1:08 pm

  8. I didn’t test his solution at all, so can’t confirm that it works.

    admin

    20 Nov 09 at 1:11 pm

  9. thanks for the hack, i was panicking for a bit when i came across this bug. also, in regards to the other hacks you were talking about, for #1 SWFWheel works pretty well and is really easy to implement.

    as for hack #2, can you go into more detail about it? i’ve encountered this as well and found it supremely annoying, but never got around to fixing it because i started on another project… thanks again!

    henry

    7 Dec 09 at 12:08 am

  10. Basically I just added some logic to check whether the values were valid or not, and if not i would just default to some arbitrary point, like the middle of the stage.

    admin

    7 Dec 09 at 7:00 am

  11. Wicked thanks for the tip, I didn’t even know that guy existed. Definately a useful solution if you are using the Flex Framework.

    A pure Flash project would not be able to use that function though, and could fallback on the setTimeout() method.

    admin

    22 Mar 10 at 5:01 pm

Leave a Reply

Spam Protection by WP-SpamFree