7 Replies Latest reply on Apr 26, 2009 5:45 PM by kglad

    Horizontal Scrollbar

    goalpost95

      I'm a noob when it comes to coding and I was wondering how I would convert this vertical scrollbar into a horizontal scrollbar

       

      heres the code:

       

       

      onClipEvent (load) {

      diff_y = bound_box._height-scroller._height;

      bounds = bound_box.getBounds(this);

      top = bounds.yMin+(scroller._height/2);

      bottom = bounds.yMax-(scroller._height/2);

      function updateScrollbar () {

      content._y = -(((scroller._y-top)/diff_y)*(content._height-bound_box._height));

      }

      friction = 0.90;

      }

       

       

      onClipEvent (mouseDown) {

      if (scroller.hitTest(_root._xmouse, _root._ymouse)) {

      startDrag ("scroller", false, scroller._x, top, scroller._x, bottom);

      scrolling = true;

      }

      }

       

       

      onClipEvent (mouseUp) {

      stopDrag ();

      scrolling = false;

      }

       

       

      onClipEvent (enterFrame) {

      if (scrolling) {

      updateScrollbar();

      newY = scroller._y;

      yspeed = (newY-oldY)*0.50;

      oldY = newY;

      done = false;

      } else if (!done) {

       

       

      oldypos = scroller._y;

      newypos = oldypos+yspeed;

      if (yspeed<-0.2 || yspeed>0.2) {

      yspeed *= friction;

      } else {

      yspeed = 0;

      done = true;

      }

       

       

      if (newypos<top) {

      yspeed = -1*yspeed*friction;

      newypos = top;

      }

      if (newypos>bottom) {

      yspeed = -1*yspeed*friction;

      newypos = bottom;

      }

       

      scroller._y = newypos;

      updateScrollbar();

      }

      }

        • 1. Re: Horizontal Scrollbar
          kglad Adobe Community Professional & MVP

          change:

           

          _y to _x

          _height to_width

          yMin to xMin

          yMax to xMax

           

          then you might want to change a few other things to make your code more readable.

          • 2. Re: Horizontal Scrollbar
            goalpost95 Level 1

            I changed everything that appeared to matter and I think i narrow it down to the clip event being mouseDown and mouseUp which obviously the mouse needs to move left or right on the scroll bar what do i need to change?

             

            onClipEvent (load) {

            diff_x = bound_box._width-scroller._width;

            bounds = bound_box.getBounds(this);

            top = bounds.xMin+(scroller._width/2);

            bottom = bounds.xMax-(scroller._width/2);

            function updateScrollbar () {

            content._x = -(((scroller._x-top)/diff_x)*(content._width-bound_box._width));

            }

            friction = 0.90;

            }

             

             

            onClipEvent (mouseDown) {

            if (scroller.hitTest(_root._ymouse, _root._xmouse)) {

            startDrag ("scroller", false, scroller._y, top, scroller._x, bottom);

            scrolling = true;

            }

            }

             

             

            onClipEvent (mouseUp) {

            stopDrag ();

            scrolling = false;

            }

             

             

            onClipEvent (enterFrame) {

            if (scrolling) {

            updateScrollbar();

            newY = scroller._x;

            yspeed = (newY-oldY)*0.50;

            oldY = newY;

            done = false;

            } else if (!done) {

             

             

            oldypos = scroller._x;

            newypos = oldypos+yspeed;

            if (yspeed<-0.2 || yspeed>0.2) {

            yspeed *= friction;

            } else {

            yspeed = 0;

            done = true;

            }

             

            effect to it

            if (newypos<top) {

            yspeed = -1*yspeed*friction;

            newypos = top;

            }

            if (newypos>bottom) {

            yspeed = -1*yspeed*friction;

            newypos = bottom;

            }

             

            scroller._x = newypos;

            updateScrollbar();

            }

            }

            • 3. Re: Horizontal Scrollbar
              kglad Adobe Community Professional & MVP

              no, that's ok.

               

              change _x to _y in the startDrag()

              • 4. Re: Horizontal Scrollbar
                kglad Adobe Community Professional & MVP

                and don't change _xmouse and _ymouse.

                • 5. Re: Horizontal Scrollbar
                  goalpost95 Level 1

                  you mean change it to this?

                   

                  onClipEvent (mouseDown) {

                  if (scroller.hitTest(_root._xmouse, _root._ymouse)) {

                  startDrag ("scroller", false, scroller._y, top, scroller._y, bottom);

                  scrolling = true;

                  }

                   

                  • 6. Re: Horizontal Scrollbar
                    goalpost95 Level 1

                    figured out an alternative, just rotating the mc with the vertical AS and it works ha ha

                    • 7. Re: Horizontal Scrollbar
                      kglad Adobe Community Professional & MVP

                      ok.