Skip to main content
Known Participant
February 4, 2013
Question

Scroll bar moves when clicked on

  • February 4, 2013
  • 1 reply
  • 2145 views

Hello.  I have a custom scroll bar that was made using AS2.  It works fine except that when you click on the bar and move it, the image shifts slightly and then doesn't line up correctly.  I don't know what's causing it to shift.  All registration points are in the upper left hand corner.  I was really hoping someone could help me with this.  Here is the code:

txt.setMask(mask)

scrollbar.onMouseDown = function() {

    if (this.hitTest(_root._xmouse, _root._ymouse) && txt._height>mask._height) {

        this.startDrag(false, scrollbarBG._x, scrollbarBG._y, scrollbarBG._x, scrollbarBG._height-this._height)

        txt.onEnterFrame = scrollThumbs;

        dragging = true

    }

};

scrollbar.onMouseUp = function() {

    stopDrag()

    dragging = false

    delete this.onEnterFrame;

};

function scrollThumbs() {

    var funkyVar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._height)/(this._parent.scrollbarBG._height-this._parent.scrollbar._height))-1)

    this.Y = (funkyVar-this._y)*.2;

    this._y += this.Y;

    if(Math.abs(funkyVar-this._y)<1 && !dragging){

        delete this.onEnterFrame

    }

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
February 4, 2013

use:

txt.setMask(mask)

scrollbar.onMouseDown = function() {

    if (this.hitTest(_root._xmouse, _root._ymouse) && txt._height>mask._height) {

        this.startDrag(false, scrollbarBG._x, scrollbarBG._y, scrollbarBG._x, scrollbarBG._height-this._height)

        txt.onEnterFrame = scrollThumbs;

        dragging = true

    }

};

scrollbar.onMouseUp = function() {

    stopDrag()

    dragging = false

    delete this.onEnterFrame;

};

function scrollThumbs() {

    var funkyVar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._he ight)/(this._parent.scrollbarBG._height-this._parent.scrollbar._height ))-1)

    this.Y = (funkyVar-this._y)*.2;

    this._y += this.Y;

    if(Math.abs(funkyVar-this._y)<1 && !dragging){

this._y=funkyVar;

        delete this.onEnterFrame

    }

}

CuwenAuthor
Known Participant
February 4, 2013

Thank you for responding.  It still shifts, though.  Was the only thing I was supposed to change was the part that was in bold?  I just added it into my original script.  Was that right or did I need to copy and paste all you wrote and rewrite my original script?  When i did that, it said that it was missing a ' somewhere.

But, the main thing is, the bar still shifts like it did before.

kglad
Community Expert
Community Expert
February 5, 2013

then get rid of that dragging variable and retry.  if that fails, you'll need to redo funkyVar

txt.setMask(mask)

scrollbar.onMouseDown = function() {

    if (this.hitTest(_root._xmouse, _root._ymouse) && txt._height>mask._height) {

        this.startDrag(false, scrollbarBG._x, scrollbarBG._y, scrollbarBG._x, scrollbarBG._height-this._height)

        txt.onEnterFrame = scrollThumbs;

    }

};

scrollbar.onMouseUp = function() {

    stopDrag()

    delete this.onEnterFrame;

};

function scrollThumbs() {

    var funkyVar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._he ight)/(this._parent.scrollbarBG._height-this._parent.scrollbar._heigh t ))-1)

    this._y += (funkyVar-this._y)*.2;

    if(Math.abs(funkyVar-this._y)<1){

this._y=funkyVar;

        delete this.onEnterFrame

    }

}