1 Reply Latest reply on Dec 10, 2010 4:47 AM by Ned Murphy

    Scroll Bar

    Nysk

      Hi,

       

      I am making a website on flash, and for one of my pages I want to have a scroll bar. I'm using an action script I found online, but for some reason the scroll button can be dragged of the scroll path, and it doesn't reach the end of the content.

       

      The code im using: (scrollTrack, is the track on which the scroll button moves, contentMain, is the actual content, scrollFace, is the button you drag uo and down to scroll, masked view, is the mask that defines the area of visible content, btnUp and btnDown are the up and down buttons.

       

      scrolling = function () {

      var scrollHeight:Number = scrollTrack._height;

      var contentHeight:Number = contentMain._height;

      var scrollFaceHeight:Number = scrollFace._height;

      var maskHeight:Number = maskedView._height;

      var initPosition:Number = scrollFace._y=scrollTrack._y;

      var initContentPos:Number = contentMain._y;

      var finalContentPos:Number = maskHeight-contentHeight+initContentPos;

      var left:Number = scrollTrack._x;

      var top:Number = scrollTrack._y;

      var right:Number = scrollTrack._x;

      var bottom:Number = scrollTrack._height-scrollFaceHeight+scrollTrack._y;

      var dy:Number = 0;

      var speed:Number = 10;

      var moveVal:Number = (contentHeight-maskHeight)/(scrollHeight-scrollFaceHeight);

       

      scrollFace.onPress = function() {

      var currPos:Number = this._y;

      startDrag(this, false, left, top, right, bottom);

      this.onMouseMove = function() {

      dy = Math.abs(initPosition-this._y);

      contentMain._y = Math.round(dy*-1*moveVal+initContentPos);

      };

      };

      scrollFace.onMouseUp = function() {

      stopDrag();

      delete this.onMouseMove;

      };

      btnUp.onPress = function() {

      this.onEnterFrame = function() {

      if (contentMain._y+speed<maskedView._y) {

      if (scrollFace._y<=top) {

      scrollFace._y = top;

      } else {

      scrollFace._y -= speed/moveVal;

      }

      contentMain._y += speed;

      } else {

      scrollFace._y = top;

      contentMain._y = maskedView._y;

      delete this.onEnterFrame;

      }

      };

      };

      btnUp.onDragOut = function() {

      delete this.onEnterFrame;

      };

      btnUp.onRollOut = function() {

      delete this.onEnterFrame;

      };

      btnDown.onPress = function() {

      this.onEnterFrame = function() {

      if (contentMain._y-speed>finalContentPos) {

      if (scrollFace._y>=bottom) {

      scrollFace._y = bottom;

      } else {

      scrollFace._y += speed/moveVal;

      }

      contentMain._y -= speed;

      } else {

      scrollFace._y = bottom;

      contentMain._y = finalContentPos;

      delete this.onEnterFrame;

      }

      };

      };

      btnDown.onRelease = function() {

      delete this.onEnterFrame;

      };

      btnDown.onDragOut = function() {

      delete this.onEnterFrame;

      };

       

      if (contentHeight<maskHeight) {

      scrollFace._visible = false;

      btnUp.enabled = false;

      btnDown.enabled = false;

      } else {

      scrollFace._visible = true;

      btnUp.enabled = true;

      btnDown.enabled = true;

      }

      };

      scrolling();

      Any help?
      TQ.

        • 1. Re: Scroll Bar
          Ned Murphy Adobe Community Professional & MVP

          I don't think it is a coding issue because if I recreate what the code tells me it involves for the scroller, the scroller works fine and cannot be dragged off its track.  You may have something set up that doesn't agree with the code.  I don't see any purpose in having the whole thing encapsulated in the scroll() function though.