Apr 24, 2009

FLASH: Fix mouse scroll wheel

/**
* To fix the stupid scroll wheel issue, AHHHH!!
*
*/
// Set the height of the flash movie into a variable,
// you could also use = Stage.height;

var nHeightOfMovie:Number = 1000;
// Initial value for the scroll position, just for reference
var nInitialScrollPossition:Number = 0;
// Number to increase the mouse scroll wheel rate, larger number
// equals greater movement
var nScrollSpeed:Number = 30;
// Create the mouse listener
var mouseListener:Object = new Object();
// Set the function to execute the javascript in order to move
// the browser scroll bar up or down
mouseListener.onMouseWheel = function(delta) {
    // Set the new position of the window for reference
    var nNewPositon:Number = nInitialScrollPossition+(-delta*nScrollSpeed);
    // this is probably not the best code but whatever!
    if (nNewPositon>(0-nScrollSpeed) && nNewPositon<nHeightOfMovie) {
        // update the window to the new position
        getURL("javascript: window.scrollTo(0,"+nNewPositon+");");
        // update the nInitalPosition so on the next
        // mouse scroll the information is current
        nInitialScrollPossition = nNewPositon;
    }
};
// attatched the listener to the mouse
Mouse.addListener(mouseListener);

No comments: