Hello
I’m pulling my hair out here trying to figure out how to get this scrollbar working. I followed a tutorial I found online and have it working except I run into problems when I move on to a different part of the site as I can’t remove some eventListeners. Here’s the code I’m using:
scrollDragger.buttonMode=true;
function scrollMyServiceContent () {
service_mc.cacheAsBitmap = true;
scrollDragger.addEventListener(MouseEvent.MOUSE_DOWN,scrollDraggerPress);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpOnStage);
var scrollbarHeight:Number = scrollbarBG.height;
var contentHeight:Number = service_mc.height;
var scrollDraggerHeight:Number = scrollDragger.height;
var maskHeight:Number = contentMasks.height;
var scrollAmout:Number = (contentHeight-maskHeight)/(scrollbarHeight-scrollDraggerHeight);
var topBound:Number = scrollbarBG.y;
var bottomBound:Number = (scrollDragger.height) +166;
var startPos:Number = service_mc.y;
var leftBound:Number = (scrollbarBG.x) +3;
var absNumSet:Number = 0;
// When scrollDragger gets pressed we do this
function scrollDraggerPress(event:MouseEvent):void {
var bounds:Rectangle = new Rectangle(leftBound, topBound, 0, bottomBound);
scrollDragger.startDrag(false, bounds);
stage.addEventListener(MouseEvent.MOUSE_MOVE, reportStageMouse);
function reportStageMouse(event:MouseEvent):void {
absNumSet = Math.abs(scrollbarBG.y - scrollDragger.y);
service_mc.y = Math.round(absNumSet * - 1.01 * scrollAmout + startPos);
}
}
// When mouse is released while dragging we do this
function mouseUpOnStage(event:MouseEvent):void {
stopDrag();
}
}
scrollMyServiceContent();
So the problem is after I move on to another part of the site I’m getting an error as the function reportStageMouse keeps running. I’ve tried removing the evenListener for reportStageMouse inside the mouseUpOnStage function but I get another error as it is all inside the scrollDraggerPress function and can’t be seen. Fairly new to all this but that’s the best I can come up with. I can’t work out how to move on from here and any help is greatly appreciated.
Thanks