AS3.0 MouseWheel on Mac OS X

I've finally found the time to port my SWFObject add-on SWFMacMouseWheel (catchy I know) to ActionScript 3.0 and SWFObject 2.0

There's now two examples in the zip, one for use with SWFObject 1.5, and a totally re-written version for use with SWFObject 2.0 (formerly SWFFix)

All you have to do in your main application class (or document class) is

Actionscript:
  1. import com.pixelbreaker.ui.osx.MacMouseWheel;
  2.  
  3. MacMouseWheel.setup( stage );

You can then add listeners to TextFields, Sprites etc etc as you normally would any other MouseEvent.

Example JavaScript to be used with the dynamic embed method

JavaScript:
  1. var vars = {};
  2. var params = { scale:'noScale', salign:'lt', menu:'false' };
  3. var attributes = { id:'testObject', name:'testObject' }; // give an id to the flash object
  4.  
  5. swfobject.embedSWF("test_as3.swf", "flashContent", "100%", "100%", "9.0.0", "js/expressInstall.swf", vars, params, attributes );
  6. swfmacmousewheel.registerObject(attributes.id);

I have updated the SWFObject 2.0 version to be more compact, and it also falls inline with the code style of SWFObject2.0. see swfmacmousewheel_src.js for the uncompressed version, deploy swfmacmousewheel2.js on your site.

Download source and demo here or view the demo online

26 Comments so far

  1. Jason / February 7th, 2008 8:07 pm

    Thanks gabe! Very nicely done!

  2. Man / February 8th, 2008 12:24 pm

    God bless you, your children, the children of your children for this wheel thing :)

  3. Chris / February 12th, 2008 7:18 am

    Thanks! You're my new best friend! :)

  4. shaun / February 25th, 2008 1:17 pm

    Yaaaaayyyyyy!!!! Thanks so much. A real lifesaver! And nicely implemented too. I like how you've stuck to the style of SWFObject 2.0

  5. Ben / February 25th, 2008 11:34 pm

    Thanks! You've made me not look so lame!

  6. Jamie McDaniel / March 1st, 2008 3:35 am

    Thanks so much for this solution to the mouseWheel on Macs. Now if I can just get the mouseWheel to work on Firefox 2 in Windows.

    Just a note for those wondering how to get it to work in a Flex mxml application, use MacMouseWheel.setup(Application.application.stage). I had to put this line of code in the applicationComplete event handler rather than the initialize or creationComplete event handlers.

  7. Jamie McDaniel / March 1st, 2008 3:42 am

    In my post above, I should have provided the detail that setting wmode=opaque breaks Flash’s MouseWheel in Firefox 2 on Windows. A javascript solution similar to your MacMouseWheel would probably be a work around until either Mozilla or Adobe fixes the problem.

  8. MyridoM / March 2nd, 2008 8:26 am

    You need to check out Chumby.com
    With your mad flash skills, you'd have some fun with it.

    MyridoM

  9. cap10subtext / March 3rd, 2008 12:37 am

    This works wonders. Thanks so much!

  10. Frederik Heyninck / March 3rd, 2008 3:28 pm

    Firefox with firebug gives a problem in the console:

    swfmacmousewheel has no properties
    http://blog.pixelbreaker.com/downloads/swfmacmousewheelas3demo/index_as3.html
    Line 15

    Any solution?

  11. gabriel / March 3rd, 2008 7:25 pm

    is that on windows? if so, i should clean that up, at present, if the OS is not a mac, it returns a null object as swfmacmousewheel.

  12. davi garms / March 4th, 2008 8:45 pm

    very good, thank you very much! now i'm stucked in another problem... :( anybody knows how to make the mouse wheel to work in windows firefox with transparent wmode? in mac it works fine with this code, even with transparent set, but in windows.... it simply doesn't work in this mode!! thanks for the attention.

  13. gabriel / March 5th, 2008 12:35 am

    davi: I'll have a look into this...

  14. gotjosh / March 10th, 2008 5:17 pm

    Hi!

    Many thanks for your tight js hack to compensate for adobe's painful laziness (or blatant prejudice) (or whatever other undogly reason that this isn't natively supported)

    I am working on an extension of the MacMouseWheel object to also send MiddleMouse Button Events.

    I have a prototype working in parallel to Gabriel's swfMacMouseWheel... here is a zip file:
    http://www.gotblogua.gotjosh.net/media/MacMouseMiddleButton.zip

    I learned a bit from here:
    http://unixpapa.com/js/testmouse.html

    Gabriel, i think this could be tighter... and i wonder if you or any of your visitors may have the fire to review the code and maybe post a better integrated version...

    please feel free to contact me with comments and or questions...

    NOTE: totally unsupported ALPHA version... i am looking for people to help me make this work better, not people to ask me how they can use it to solve their problems... it will probably make more problems than it solves at this point ;-)

  15. muhabbet / March 20th, 2008 1:11 pm

    This works wonders. Thanks so much!

  16. thibaud / March 22nd, 2008 11:48 am

    Thanks a lot for the script Gabriel.
    one thing:
    I just installed safari 3.1 on windows, I can't believe it also has the mousewheel amputated for flash content. You might want to add a check for the few ppl using it as well.

  17. Shinobu / March 25th, 2008 11:21 pm

    Yep I just tried it on Safari for windows.. Doesn't work :/ (Safari Ver 3.1)

  18. Dan / March 27th, 2008 7:26 pm

    This class was so simple to implement and solves such a huge problem. Thanks very much

  19. Pete / March 31st, 2008 2:05 pm

    Gabriel, you're distributing this with svn files included starting at /ui level. Thanks for sharing your code.

  20. ketch / April 2nd, 2008 7:07 pm

    I don't understand, i have safari 3.1 on windows, and i can't run the demo online ?

  21. Tenchi / April 5th, 2008 9:37 pm

    hey thanks for this wonderful script , very easy to implement works great

    please let us know if can fix the wmode problem.
    a fix for safari on windows would aslo be great :D

    keep up the good work !

  22. Railk / April 8th, 2008 12:27 am

    A big thanks for this really useful script that really works great.

    For those who want it, i made a small fix for the script to work on safari for windows that you can find here (everything is explain on the readme.txt inside the rar)

    http://railkill.free.fr/safari/safariFixed.rar

    you can view a working sample here:
    http://railkill.free.fr/monolog/

    Not sure it's the best solution, but it works while waiting for Gabriel to update his script ^^.

    Thx again for you script !

  23. Wheener / April 30th, 2008 7:16 pm

    You code just made in onto a MOMA minro site

    http://media.moma.org/subsites/2008/olafureliasson/#/intro/

  24. Wheener / April 30th, 2008 7:17 pm

    Your code just made in onto a MOMA minro site

    http://media.moma.org/subsites/2008/olafureliasson/#/intro/

  25. simurai / May 7th, 2008 5:03 pm

    I noticed something funny with the fullscreen mode.. on Mac Safari it works in normal mode but not in fullscreen mode and on Windows Safari it's the opposite.. it doesn't work in normal mode, but it DOES work in fullscreen mode. Pretty strange.. ;-) Note: I'm using the new JS but still the old AS 2.0 script.

  26. nl-x / May 8th, 2008 10:14 am

    This sounds good.
    However I primarily had given up on Mac Scrollwheeling and was searching for a solution on another problem that could be solved by this if ported for Windows...

    The thing is: to give a Flash App focus from the browser (to be able to start typing in a Flash Text Field directly after visiting the site), you need to give the Flash App focus from JavaScript myObject.focus(), and in Flash give the focus to the component needing to get focus by doing for example creationComplete="myComponent.setFocus();" (Flex).
    However, in FireFox, the javascript myObject.focus() will only work if the Flash object is loaded using wmode="opaque". And that again breaks scroll wheel functionality in Windows FireFox.

    Question:
    - Are there any known side-effects from this script by PixelBreaker?
    - Is there any Windows Port (to be build by anyone) ?

    Kind regards,
    nl-x

Leave a reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image