Hello.
I am currently making a site that uses Oringe.com’s old fullscreen scrollbar. It’s really perfect.
I was just wondering how hard it would be to implement some sort of scrollTo function. For example, I would have all of the content inside the scrollbar window. In this content, I would have a list of movieclips acting as buttons that would scroll to a specific y value (all of which would be in say 200px increments).
so I would love to have a simple function where I could execute scrollTo(n); where n=a givin y value. Basically acting as HTML anchor tags.
It seems like it wouldn’t be too hard, but the code is a bit over my head.
Here is the code (the fla is located at http://www.oringe.com/download/blurScroll.fla):
Thank You!
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////BLUR SCROLL v 0.1
////copyright (c) 2006 Benjamin Wong
////http://www.oringe.com
////
////NOTICE:
////Feel free to re-use and modify, but if you do use it, please link
////back to www.oringe.com! Thank you!
////
//////////////////////////////////////////////////////////////////////
//MODIFY the below variables to suit your needs:
//
//set your flash stage width here:
initStageWidth = 872;
//
//set how many pixels you want your content to move when you move
//the mousewheel here:
mouseWheelIncrement = 90;
//////////////////////////////////////////////////////////////////////
//DO NOT TOUCH the below code
//unless, of course, you want to change the script and
//workings of this code.
////////////////////////////
//import the blur filter (requires Flash 8 & actionscript 2)
import flash.filters.BlurFilter;
//blur = new BlurFilter(0, 1, 1);
////////////////////////////
//create a listener for the mouse wheel so the mouse wheel works
mouseListener = new Object();
mouseListener.onMouseWheel = function(delta) {
if (delta < 0) {
mainTargetY -= mouseWheelIncrement;
if (mainTargetY < Stage.height - main._height) {
mainTargetY = Stage.height - main._height;
}
}
if (delta > 0) {
mainTargetY += mouseWheelIncrement;
if (mainTargetY > mainInitY) {
mainTargetY = mainInitY;
}
}
}
Mouse.addListener(mouseListener);
////////////////////////////
//actions for scrollbar
//first init some frequently used variables
mainInitY = main._y;
scrollbarInitY = scrollbar.scrollbutton._y;
scrollOn = false;
mainTargetY = mainInitY;
scrollbarTargetY = scrollbarInitY;
//don't want to use hand cursor for scrollbar
scrollbar.scrollbutton.useHandCursor = false;
//actions for scrollbar button behavior
scrollbar.scrollbutton.onRollOver = function() {
if (!scrollOn) {
this.gotoAndPlay("over");
}
}
scrollbar.scrollbutton.onDragOver = scrollbar.scrollbutton.onRollOver;
scrollbar.scrollbutton.onRollOut = function() {
this.gotoAndPlay("out");
}
scrollbar.scrollbutton.onPress = function() {
scrollOn = true;
this.startDrag(false, this._x, scrollbarInitY, this._x, scrollbarInitY + scrollAreaHeight);
}
scrollbar.scrollbutton.onMouseUp = function() {
if (scrollOn) {
scrollOn = false;
this.stopDrag();
if (!scrollbar.scrollbutton.hitTest(_xmouse, _ymouse)) {
scrollbar.scrollbutton.gotoAndPlay("out");
}
}
}
//this is where the animation happens, within this function:
scrollbar.scrollbutton.onEnterFrame = function() {
if (scrollOn) {
mainTargetY = mainInitY-(main._height-Stage.height)*(scrollbar.scrollbutton._y - scrollbarInitY)/scrollAreaHeight;
} else {
scrollbarTargetY = -(main._y - mainInitY)*scrollAreaHeight/(main._height - Stage.height) + scrollbarInitY;
if (Math.abs(scrollbar.scrollbutton._y - scrollbarTargetY) > 0.2) {
scrollbar.scrollbutton._y += (scrollbarTargetY - scrollbar.scrollbutton._y)/2;
}
}
if (Math.abs(main._y - mainTargetY) > 0.2) {
//this is where we calculate the blur distance
mainOldY = main._y;
main._y += Math.ceil((mainTargetY - main._y)/2);
mainMovement = mainOldY - main._y;
//we flur the blur distance for performance gains
//(in theory, at least; this hasn't been tested)
blur.blurY = Math.floor(Math.abs(mainMovement));
main.filters = [blur];
}
}
////////////////////////////////////
//actions for stage resizing
Stage.align = "T";
Stage.scaleMode = "noScale";
resizer = new Object();
resizer.onResize = function () {
scrollbar._x = Math.ceil((Stage.width - initStageWidth)/2 + initStageWidth - scrollbar._width);
scrollAreaHeight = Stage.height - scrollbarInitY*2 - scrollbar.scrollbutton._height;
}
Stage.addListener(resizer);
resizer.onResize();