# Scrollbar problem. Please help!

**URL:** <https://forum.kirupa.com/t/scrollbar-problem-please-help/330579>\
**Category:** flash\
**Created:** [February 12, 2013, 10:16pm UTC](https://forum.kirupa.com/t/scrollbar-problem-please-help/330579 "2013-02-12T22:16:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![siosio](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@siosio](https://forum.kirupa.com/u/siosio)\
**Post date:** [February 12, 2013, 10:16pm UTC](https://forum.kirupa.com/t/scrollbar-problem-please-help/330579/1 "2013-02-12T22:16:10Z")

</div>

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
