I have a custom scroll bar with two buttons on each end and a dragger. My dragger works well but my buttons do not. When I mouse up the content resets to the last x position of my dragger. So if I don’t do any dragging and I click my scrollLeft button it advanced 50 to the left but as soon as I move the mouse the content resets. I think it’s a problem with my stage event listeners but I am not sure or even how to resolve this issue. I attached a zip file as well. Any help on this appreciated.
ActionScript Code:
[LEFT]scrollBar_mc.[COLOR=#000080]scrollLeft[/COLOR].[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]CLICK[/COLOR], moveLeft, [COLOR=#000000]**false**[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000]**true**[/COLOR][COLOR=#000000])[/COLOR];
scrollBar_mc.[COLOR=#000080]scrollRight[/COLOR].[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]CLICK[/COLOR], moveRight, [COLOR=#000000]false[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000]true[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]function[/COLOR] moveLeftCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
mcHolder.[COLOR=#000080]x[/COLOR] -= [COLOR=#000080]50[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]function[/COLOR] moveRightCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]mcHolder.[COLOR=#000080]x[/COLOR] != [COLOR=#000080]25[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
mcHolder.[COLOR=#000080]x[/COLOR] += [COLOR=#000080]50[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]function[/COLOR] scrollColorContentCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]// Set variables[/COLOR]
[COLOR=#000000]var[/COLOR] scrollbarWidth:[COLOR=#0000ff]Number[/COLOR] = scrollBar_mc.[COLOR=#000080]scrollMask[/COLOR].[COLOR=#0000ff]width[/COLOR];
[COLOR=#000000]var[/COLOR] scrollDraggerWidth:[COLOR=#0000ff]Number[/COLOR] = scrollBar_mc.[COLOR=#000080]scrollDragger[/COLOR].[COLOR=#0000ff]width[/COLOR];
[COLOR=#000000]var[/COLOR] maskWidth:[COLOR=#0000ff]Number[/COLOR] = scrollBar_mc.[COLOR=#000080]scrollMask[/COLOR].[COLOR=#0000ff]width[/COLOR];
[COLOR=#000000]var[/COLOR] leftBound:[COLOR=#0000ff]Number[/COLOR] = scrollBar_mc.[COLOR=#000080]scrollMask[/COLOR].[COLOR=#000080]x[/COLOR];
[COLOR=#000000]var[/COLOR] rightBound:[COLOR=#0000ff]Number[/COLOR] = scrollBar_mc.[COLOR=#000080]scrollMask[/COLOR].[COLOR=#000080]width[/COLOR]-scrollDraggerWidth;
[COLOR=#000000]var[/COLOR] startPos:[COLOR=#0000ff]Number[/COLOR] = mcHolder.[COLOR=#000080]x[/COLOR];
[COLOR=#000000]var[/COLOR] absNumSet:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]60[/COLOR].[COLOR=#000080]5[/COLOR];
[COLOR=#808080]//set starting position of dragger[/COLOR]
scrollBar_mc.[COLOR=#000080]scrollDragger[/COLOR].[COLOR=#000080]x[/COLOR] = scrollBar_mc.[COLOR=#000080]scrollMask[/COLOR].[COLOR=#000080]x[/COLOR];
[COLOR=#808080]*// Event Listeners*[/COLOR]
scrollBar_mc.[COLOR=#000080]scrollDragger[/COLOR].[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_DOWN[/COLOR], scrollDraggerPress, [COLOR=#000000]**false**[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000]**true**[/COLOR][COLOR=#000000])[/COLOR];
scrollBar_mc.[COLOR=#000080]scrollDragger[/COLOR].[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_UP[/COLOR], mouseUpOnStage, [COLOR=#000000]**false**[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000]**true**[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#0000ff]stage[/COLOR].[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_UP[/COLOR], mouseUpOnStage[COLOR=#000000])[/COLOR];
[COLOR=#808080]*// When scrollDragger gets pressed we do this*[/COLOR]
[COLOR=#000000]**function**[/COLOR] scrollDraggerPress[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#000000]**var**[/COLOR] contentWidth:[COLOR=#0000ff]Number[/COLOR] = mcHolder.[COLOR=#0000ff]width[/COLOR];
[COLOR=#000000]**var**[/COLOR] scrollAmount:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000000]([/COLOR]contentWidth-maskWidth[COLOR=#000000])[/COLOR]/[COLOR=#000000]([/COLOR]scrollbarWidth-scrollDraggerWidth[COLOR=#000000])[/COLOR];
[COLOR=#808080]*// Set bounds using some of the scroller BG properties claimed above*[/COLOR]
[COLOR=#000000]**var**[/COLOR] bounds:Rectangle = [COLOR=#000000]**new**[/COLOR] Rectangle[COLOR=#000000]([/COLOR]leftBound, [COLOR=#000080]60[/COLOR].[COLOR=#000080]5[/COLOR], rightBound[COLOR=#000000])[/COLOR];
scrollBar_mc.[COLOR=#000080]scrollDragger[/COLOR].[COLOR=#0000ff]startDrag[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]**false**[/COLOR], bounds[COLOR=#000000])[/COLOR];
[COLOR=#0000ff]stage[/COLOR].[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_MOVE[/COLOR], reportStageMouse[COLOR=#000000])[/COLOR];
[COLOR=#000000]**function**[/COLOR] reportStageMouse[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
absNumSet = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]abs[/COLOR][COLOR=#000000]([/COLOR]scrollBar_mc.[COLOR=#000080]scrollMask[/COLOR].[COLOR=#000080]x[/COLOR] - scrollBar_mc.[COLOR=#000080]scrollDragger[/COLOR].[COLOR=#000080]x[/COLOR][COLOR=#000000])[/COLOR];
mcHolder.[COLOR=#000080]x[/COLOR] = + [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]round[/COLOR][COLOR=#000000]([/COLOR]absNumSet * - [COLOR=#000080]1[/COLOR] * scrollAmount + startPos[COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]*// When mouse is released while dragging we do this*[/COLOR]
[COLOR=#000000]**function**[/COLOR] mouseUpOnStage[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]stopDrag[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
scrollColorContentCOLOR=#000000[/COLOR];
[/LEFT]