• QuickTip: Scrolling Only in SWF, not on Page.

    Posted on January 18th, 2010 Rasmus Wriedt Larsen 6 comments
    This entry is part 2 of 4 in the series Quick Tips

    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:

    (Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

    (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):

    (Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

     

    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).

    (Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

     

    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 :)

    Share this Article
    • Digg
    • Sphinn
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • MySpace
    • StumbleUpon
    • TwitThis
     

    4 responses to “QuickTip: Scrolling Only in SWF, not on Page.” RSS icon


    2 Trackbacks / Pingbacks

    • [...] auch von browser zu browser unterschiedlich sein das da z.b. ist ok: QuickTip: Scrolling Only in SWF, not on Page. | Rasmus Wriedt Larsen – Flash Game Development __________________ die ultimative antwort auf alle programmierfragen: der debugger! – vor eine [...]

    • [...] da nach, und probiere die logig umzustellen. also via javascript das browser-scrollen anschalten. QuickTip: Scrolling Only in SWF, not on Page. | Rasmus Wriedt Larsen – Flash Game Development __________________ die ultimative antwort auf alle programmierfragen: der debugger! – vor eine [...]

    Leave a reply