In OpenLaszlo, scrollbars don’t automatically scroll with the mouse wheel. I guess the reason behind this is that scrollbars are very free-form. As a developer, you can make anything scroll, so it would be restrictive if the scrollbars were to respond to mouse wheel events in a predefined way.
To see how to use a scrollbar in OpenLaszlo, see my earlier post on the subject.
It’s really easy to trap mouse wheel events in OpenLaszlo. All you do is listen for the onmouswheeldelta event from the LzKeys service. That’s also the service that sends global keyboard events, by the way. The onmouswheeldelta event sends an argument, which tells you how much the wheel moved, and in what direction (it’s either a positive or a negative number).
To tie this to a scrollbar, you probably want to ensure that the mouse is actually overing above the view you want to scroll. Again, in OpenLaszlo, that’s really easy. There’s a containsPt() method on view, that tells you whether a given point (x,y) is within that view’s coordinate space. And to find the mouse position in a given views coordinate space, you simply call:
LzView.getMouse(“x”) and LzView.getMouse(“y”)
So here’s the application in action. Note that you might need to bring focus from the browser to the SWF by clicking once on the SWF:
Enjoy! (Here's the source to a Mouse Wheel Example).
Doesn’t appear to work with two-fingered scrolling on OS X MacBook :(.
Did you click on the app first, to transfer focus to it? I’m using an IBM Thinkpad, and for me, it works with the mouse wheel, the right-hand-edge of the trackpad, and the scrolly-button/trackpoint combination.
Also, when you start scrolling, you need to be hovering over that particular window for it to scroll.
On the Mac, the two-fingered scroll gesture does actually generate scroll wheel events, but the Mac Flash player does not caputre these events. However, if you run Flash in a Windows browser in Parallels, it actually does work. Not that that helps 🙂
can you post the source of the example plz ? or send it to me with a mail
and another question,does it work in a combobox?
thanks a lot ^^
Hi jio,
I’ve posted a simple code example to the end of the post above.
You asked about whether this could be done to a combobox. That’s trickier, because the actual list that a combobox contains is really floating at the canvas level. So it’s harder to get at. It’s certainly something you could modify in the comobox (or datacombobox) component itself. If you want to try, the source code is in lps/components/floatinglist.lzx.
-Antun
thanks a lot ~~
Hi Antun,
I’m using above logic to activate mouse wheel in a view, it’s giving small problem when open a window on this view and scroll on a window, view is scrolling automatically, How to stop view scrolling whenever window is open on it.
Thanks a lot.
Vishnu.
thanks! I’m using 4.6.1 and had to reference lz.Keys instead of LzKeys.
Hey Chris,
Thanks for posting that. There’s more information about namespace changes on this post:
http://www.antunkarlovac.com/blog/2008/09/15/the-lz-namespace/
-Antun
Same for me, I am using two-fingered scrolling on OS X MacBook
After focus on app, mouse wheeling scrolls the whole page.