After reading an awesome article by Peter McBride called JavaScript and VBScript Injection in ActionScript 3, I've put together a single as3 class that fixes the MOUSE_WHEEL problem without the need for any external javascript code. It works on Safari, FireFox and Opera and probably Chrome when it becomes available on the Mac.
The trick was to inject the mouse handling javascript code using ExternalInterface. The code finds the DOM node for itself, intercepts and passes the mouse wheel events which are then disributed to the current InteractiveObject under the cursor.
An example of initialization would be:
class awesomeapp extends Sprite {
public function awesomeapp() {
addEventListener(Event.ADDED_TO_STAGE, stage_init);
}
private function stage_init(e:Event):void {
MacMouseWheelHandler.init(stage);
addEventListener(MouseEvent.MOUSE_WHEEL, wheel_event);
}
}
Download the source (MIT license).

17 comments:
Cool stuff...I'm trying it out.
I just added a ":void" to the function in line 60 since FlexBuilder was bitchin' about your function not having a return value.
Good job man!
Dude, frikin' lifesaver, really easy to use, and works out of the box in my Flex project. Thanks a ton for sharing this!
Be sure to drop a vote for the bug itself in the Adobe bug tracker:
http://bugs.adobe.com/jira/browse/FP-503
This is terrific, but could you write a short example how to use it…i cant get it by my self…this would be nice :c)
Nice class, but it disables page scrolling in browser at all. Not only when mouse is over flash.
I tried to fix it, but no luck.
Hi,
I tweaked this code to also allow the wheel to work on pc when wmode is being used in the *object* or *embed* tag.
code is here:
http://code.google.com/p/flex-wmode-mousewheel-handler-example/
Hi, I am a novice Flash developer. Can someone please explains to me in basic steps (1,2,3) how to make this work on a Mac? Where do I put the MacMouseWheelHandler.as file
I am using this actionsctipt to scroll through my timeline
function scrollTime (event:MouseEvent):void
{
if (event.delta < 0)
{
nextFrame();
timeFrame ++;
trace (timeFrame);
scrollAxial_mc.value = timeFrame;
}
else
{
prevFrame();
timeFrame --;
scrollAxial_mc.value = timeFrame;
if (timeFrame <1 )
{
timeFrame = 1;
}
}
}
Many thanks to whoever answers this question. Help me please.
Hello,
I´ve noticed that in safari the scrollbars of the browser stopped working is there a solution so that we can switch on/off the flash mousewheel support?
Thanks in advance
Super çà marche parfaitement pour moi, preuve à l'appuie :
http://www.centre-culturel-de-la-sar de la sarthe.com
allz dans une des rubriques où il y a un scroll !
Great it works for me !
the evidences on http://www.centre-culturel-de-la-sarthe.com
Thank you !
Lovely!
Crazy easy to implement and works great!
<mx:Application ... creationComplete="init()"
<mx:Script>
import com.earthbrowser.MacMouseWheelHandler;
public function init():void{
this.addEventListener(Event.ADDED_TO_STAGE, stage_init);
public function stage_init(e:Event):void {
MacMouseWheelHandler.init(stage);
}
</mx:Script>
.
.
.
Hi there,
Can someone post an example? I tried inserting the code into the timeline as well as referencing it via the Document class.
Thank you!
ridiculous simply to implement!
Thanks a lot for this one!
For timeline-coders:
put the com folder in the right place and import the class using:
import com.earthbrowser.ebutils.MacMouseWheelHandler;
MacMouseWheelHandler.init(stage)
and there you go
Awesome! Thank you...
tomek
Just out of curiosity, is there any particular reason eb.findSwf iterates through the objects and embeds like it does rather than just using document.getElementById?
I just reread the code and figured out why, though it still seems like there should be a better way to do this.
this is by far the best solution on this matter (adobe should fix this) Thank you so much
Post a Comment