QuickTip: Scrolling Only in SWF, not on Page.
This Quick Tip will show you how to stop simultaneous scrolling on a page and in SWF.
This is just a little test SWF, showing how a SWF would normally act when using the scroll wheel, go ahead and try it out:
(I just made a MouseEvent.MOUSE_WHEEL
evenlistener on the stage here, then changing the text fields scrollV
property)
I know of two methods to solve this problem, I will introduce both of them and show how they are working, then I will tell a little about the difference and lastly show that actually only one of them works! (Thanks to the wonderful FGL forum)
Method one:
You need to download the source here, then put it in your library. When you need to use it, import:
import ru.etcs.ui.MouseWheel; |
Then in the constructor for your document class call:
MouseWheel.capture ( ) ; |
If you want to, you can also release it again, by calling:
MouseWheel.release ( ) ; |
and it has a property showing if the mouseWheel is locked or not:
MouseWheel.captured |
Here is a test of it (try scrolling now, it still works, but the page won’t scroll anymore):
Method two:
You need to download the source here, then put it in your library. When you need to use it, import:
import com.spikything.utils.MouseWheelTrap |
Then in the constructor for your document class call:
MouseWheelTrap.setup ( stage ) ; |
Here is a test of it (it works just as good as the other one it seems).
So what is the difference?
The big difference is how they do it:
The first one uses the byteArray and localConnection functions in AS3, to create an AS2 SWF that will prevent most browsers from getting the scroll event. (All credits goes to Steven from Yama Games for explaining this.)
The second one is using JavaScript to force the browser to keep the scroll location the same place when someone uses the scroll wheel over the SWF. This is just embedded in the class, not in the page as usually seen. (Again Steven has a expert comment saying it might not work on Facebook – as I still don’t have an account, I can’t go test it out myself).
Bonus info:
When compiling the memory difference is only 708 bytes, so no big difference there (Method 2 is smaller than Method 1).
Only one of them works!
So I just tested them all out on Kongregate, and it shows that only method 1 works!
So I will just stick with method one!
You can test it out yourselves here:
Without any script.
With method one.
With method two.
Happy coding :)
- QuickTip: Execute Code After Animaiton
- QuickTip: Scrolling Only in SWF, not on Page.
- QuickTip: Managing Saved Data (SharedObject)
- QuickTip: Understanding Right Click Menus (ContextMenu)
- QuickTip: Stopping an Event
- QuickTip: Avoid Firefox popup-blocker When Using navigateToUrl
- QuickTip: Inline If-Then-Else Statement
- QucikTip: Trace an Array With Correct Formatting