4 Replies Latest reply on Jun 28, 2006 3:00 PM by kglad

    ondrag dragging distance

      I'm using ondrag with a custom made scrollbar, everything works great, buttons, track clicking etc. and dragging too... except that I have to move the draggable slider by a set amount of pixels. The slider adjusts it's height proportionaly to the number of pictures there are to scroll through, clicking the scroll buttons moves the slider by this proportional amount. I've used on drag to drag the slider but this moves it one pixel at a time. It can also be stopped at any point.

      If the slider height is 30 pixels, for example, and it is dragged 15 pixels down, the slider is then positioned exactly between two of the points that it would go to if the scrollbars arrowbuttons were clicked. I'm trying to update the position of the slider after stopdrag is called so that it 'snaps' to the nearest 'position'. ie, The slider starts at 0 and has a height of 30, it is dragged down and released. After the stopdrag is called, another function is called, adjustPosition(). which should snap the slider to the correct position. So if the above slider was dragged and released anywhere between 1 and 14 pixels, the slider snaps to 0 pixels. If the slider is released after 14-29 pixels the slider snaps to 30.

      I'm able to get the last position of the slider before the drag using a variable and using ._ymouse I get the position of it after the drag. What I don't know how to do is decide which point the slider should be snapped to. The slider height (and the snapping position) is based on the number of images there are to display (as slider height is proportional to the number of images).

      Eventually I made an array, like this:

      temp[0]["start"] = 0;
      temp[0]["stop"] = 29;
      temp[1]["start] = 30;
      temp[1]["stop"] = 59;

      this array was built using actionscript because there is no way I can tell at author time how many images there are to display.

      I then used a for loop to go through the array comparing the start and stop positions to the sliders current position after dragging trying to decide how much of the slider was in temp[0]'s start and stop range and how much was in temp[1].

      This sort of worked but not always and seems very complicated too. Is there anyway of specifying how many pixels startdrag drags a movieclip by? Does anyone know how I can do what I want to do?
        • 1. Re: ondrag dragging distance
          stephen_c_ Level 1
          Or even understand what I just posted?!? ;-)
          • 2. Re: ondrag dragging distance
            jthereliable Level 1
            If the scroll bar automatically adjusts its own height due to some of your other AS, then use this code. Put it into the scrollbar's movieclip. (or modify it to how it fits)

            furthestPoint is how far down it can go, basically, set this to how big the window is
            startingPoint is where it starts, set this to where the window starts (or something) play around, you'll understand
            In mouseDown part, if(this.hitTest(_root._xmouse,_root._ymouse,true)) is just how I make to check if you clicked on a movie clip.

            this.startDrag(false,_x,_height/2+startingPoint,_x,furthestPoint-_height/2+startingPoint) is how it starts dragging.
            [param 1] It doesn't lock the mouse to the center of the movieclip
            [param 2] It makes it so the maximum place it can go left is _x
            [param 3] It makes it so that's the maximum point it can move up
            [param 4] It makes it so the maximum place it can go right is _x (with param 2 like that, it makes it stationary in _x)
            [param 5] It makes it so that's the maximum point it can move down

            and when you let go of your mouse, it "this.stopDrag()" or stops dragging.

            I'm working to locate where (percent-wise) the bar is. Please wait.
            • 3. Re: ondrag dragging distance
              jthereliable Level 1
              Ok, use this:
              to find where the scrollbar is in percentage to how much it can go.
              • 4. Re: ondrag dragging distance
                kglad Adobe Community Professional & MVP
                i don't think you want to do what you just stated you want to do. that is, it makes no sense to snap the slider to another positions after a stopDrag(). though, you may want to snap your pictures to a particular position.

                your slider can move from one extreme position to another. when your slider is at one extreme, your pictures are at one extreme (of one or more of their properties, usually their _x or _y property) and when your slider is at its other extreme, your pictures are at their other extreme. when the slider is between the two extreme positions, the pictures are between their extremes. usually, linear interpolation is used to set the picture's position based on the slider's position and this requires solving 2 (linear) equations in two unknowns.

                for example, if your slider moves from sliderMin to sliderMax and your pictures are to scroll from picsMin to picsMax, you solve:

                picsMin=sliderMin*a + b;
                picsMax=sliderMax*a +b;



                and now your picsPosition is given by:

                picsPosition=sliderPosition*a + b;