Accelerated Mousewheel Scrolling (with easing)

Example: http://img145.imageshack.us/my.php?image=accelscrolldb6.swf

Example uses a textfield and MC Tween for motion.
You can use it on movieclips, textfields, anything. The concept is using setInterval to determine how much the mousewheel is spunned in a short 100ms time span and then a function to apply the scroll based on the calculated number of steps. So you can also use it other than scrolling. It will work on any properties that can be controlled over time.

Hope you like it! :slight_smile:

Source FLA (20KB): http://aendirect.com/source/accel_scroll.zip

Actionscript

stop();

#include "mc_tween2.as"

var story:String = "<font size='14'>Insert lots of text here...</font>";

mcText.createTextField("theText", this.getNextHighestDepth(), 0, 0, 400, 500);
mcText.theText.wordWrap = true;
mcText.theText.autoSize = true;
mcText.theText.html = true;
mcText.embedFonts = true;
var fmt:TextFormat = new TextFormat();
fmt.font = "Arial";
fmt.color = 0x000000;
mcText.theText.setTextFormat(fmt);

mcText.theText.htmlText = story;


// Scroll-related
var totalScroll:Number = 0;
var steps:Number = 0;
var line:Number = 17; // 17: line-height, 3: numbers of lines to scroll
var linesToScroll:Number = 3;
var scrollDist:Number;
var destination:Number;
var maxTop:Number = Stage.height - mcText._height;
var interval:Number = 100;


function applyScroll(delta) {
    
    steps = Math.floor(totalScroll/delta);
    scrollDist = (line * linesToScroll) * steps;
    
    var scrollSpeed:Number = 0.5 + 0.1 * steps;
    
    if(delta < 0) {

        destination = mcText._y - scrollDist;
        
        // Ensures the scroll stays within boundaries
        if(destination < maxTop) {
            destination = maxTop;
        }

    } else if (delta > 0) {
        
        destination = mcText._y + scrollDist;
        
        // Ensures the scroll stays within boundaries
        if(destination > 0) {
            destination = 0;
        }
    }
    
    mcText.ySlideTo(destination, scrollSpeed, "easeOutExpo");
    
    totalScroll = 0;
    steps = 0;
    clearInterval(applyScrollInterval);
}


var mouseLis:Object = new Object();
mouseLis.onMouseWheel = function(delta) {
    totalScroll += delta;
    clearInterval(applyScrollInterval);
    applyScrollInterval = setInterval(applyScroll, interval, delta);
};

Mouse.addListener(mouseLis);