6 Replies Latest reply on Feb 22, 2012 5:09 AM by Ned Murphy

    why wont this script work???

    janineabc Level 1

      Hi,

       

      I have previously used this script to make a portrait scroll bar which works perfectly, however i have altered the script to work in a landscape scroll bar by altering the x and y axis and switching out the height for width. However a part of it wont work...The left and right arrows work correctly however the scroll bar does not move and I can not for the life of me figure out why.

       

      Does anyone have any ideas as to what ive missed or done wrong?

       

      Thanks in advance

       

       

      scrolling = function () {

       

      var scrollWidth:Number = scrollTrack._width;

      var contentWidth:Number = contentMain._width;

      var scrollFaceWidth:Number = scrollFace._width;

      var maskWidth:Number = maskedView._width;

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

      var initContentPos:Number = contentMain._x;

      var finalContentPos:Number = maskWidth-contentWidth+initContentPos;

      var left:Number = scrollTrack._y;

      var top:Number = scrollTrack._x;

      var right:Number = scrollTrack._y;

      var bottom:Number = scrollTrack._width-scrollFaceWidth+scrollTrack._x;

      var dy:Number = 0;

      var speed:Number = 10;

      var moveVal:Number = (contentWidth-maskWidth)/(scrollWidth-scrollFaceWidth);

       

      scrollFace.onPress = function() {

        var currPos:Number = this._x;

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

        this.onMouseMove = function() {

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

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

        };

      };

      scrollFace.onMouseUp = function() {

        stopDrag();

        delete this.onMouseMove;

      };

      btnUp.onPress = function() {

        this.onEnterFrame = function() {

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

          if (scrollFace._x<=top) {

           scrollFace._x = top;

          } else {

           scrollFace._x -= speed/moveVal;

          }

          contentMain._x += speed;

         } else {

          scrollFace._x = top;

          contentMain._x = maskedView._x;

          delete this.onEnterFrame;

         }

        };

      };

      btnUp.onDragOut = function() {

        delete this.onEnterFrame;

      };

      btnUp.onRelease = function() {

        delete this.onEnterFrame;

      };

      btnDown.onPress = function() {

        this.onEnterFrame = function() {

         if (contentMain._x-speed>finalContentPos) {

          if (scrollFace._x>=bottom) {

           scrollFace._x = bottom;

          } else {

           scrollFace._x += speed/moveVal;

          }

          contentMain._x -= speed;

         } else {

          scrollFace._x = bottom;

          contentMain._x = finalContentPos;

          delete this.onEnterFrame;

         }

        };

      };

      btnDown.onRelease = function() {

        delete this.onEnterFrame;

      };

      btnDown.onDragOut = function() {

        delete this.onEnterFrame;

      };

       

      if (contentWidth<maskWidth) {

        scrollFace._visible = false;

        btnUp.enabled = false;

        btnDown.enabled = false;

      } else {

        scrollFace._visible = true;

        btnUp.enabled = true;

        btnDown.enabled = true;

      }

      };

      scrolling();

        • 1. Re: why wont this script work???
          Ned Murphy Adobe Community Professional & MVP

          Can you isolate only the code that applies to the part that doesn't work.  It makes it easier to focus on the problemed area.

          • 2. Re: why wont this script work???
            janineabc Level 1

            sorry should have said...its the aspect relating to "scrollFace" which is mentioned throughout..ive marked it out in bold and taken out anything unrelivant.

             

            Thanks

             

            So its:

             

            scrolling = function () {

            var scrollFaceWidth:Number = scrollFace._width;

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

            var bottom:Number = scrollTrack._width-scrollFaceWidth+scrollTrack._x;

            var moveVal:Number = (contentWidth-maskWidth)/(scrollWidth-scrollFaceWidth);

             

            scrollFace.onPress = function() {

              var currPos:Number = this._x;

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

              this.onMouseMove = function() {

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

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

              };

            };

            scrollFace.onMouseUp = function() {

              stopDrag();

              delete this.onMouseMove;

            };

            btnUp.onPress = function() {

              this.onEnterFrame = function() {

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

               if (scrollFace._x<=top) {

                 scrollFace._x = top;

                } else {

                 scrollFace._x -= speed/moveVal;

                }

                contentMain._x += speed;

               } else {

                scrollFace._x = top;

                contentMain._x = maskedView._x;

                delete this.onEnterFrame;

               }

             

            btnDown.onPress = function() {

              this.onEnterFrame = function() {

               if (contentMain._x-speed>finalContentPos) {

               if (scrollFace._x>=bottom) {

                 scrollFace._x = bottom;

                } else {

                 scrollFace._x += speed/moveVal;

                }

                contentMain._x -= speed;

               } else {

               scrollFace._x = bottom;

                contentMain._x = finalContentPos;

                delete this.onEnterFrame;

               }

             

            if (contentWidth<maskWidth) {

              scrollFace._visible = false;

              btnUp.enabled = false;

              btnDown.enabled = false;

            } else {

              scrollFace._visible = true;

              btnUp.enabled = true;

              btnDown.enabled = true;

            • 3. Re: why wont this script work???
              Ned Murphy Adobe Community Professional & MVP

              Even with that reduction it is at best a tangle of code to try to reason out.  I think I see you have nested functions at least two levels deep, possibly further since I can't see where the initial one ends, and nesting functions is best avoided and more often unnecessary.... 

               

              scrolling = function () {

                  scrollFace.onPress = function() {

                          this.onMouseMove = function() {

               

                          }

                   };

              };

               

              Since you say the problem is that the scrollbar does not move, does it not move relative to pushing the buttons or does it not move relative to dragging it.

              • 4. Re: why wont this script work???
                janineabc Level 1

                Hi,

                 

                I've had a bit of a play with it and i managed to make it register that there is a scroll bar there, however it appears way to the right even beyond the right hand arrow and as soon as i click on the arrow button the scroll completely disappears. So the scroll bar doesn’t move either way at the minute.

                 

                I will have a play and see how I go.

                 

                Thanks

                • 5. Re: why wont this script work???
                  janineabc Level 1

                  Hi,

                   

                  Throught I would let you know that I've got it working..the script didnt need editing at all...it was the scroll element that was working back to front. So i simply rotated it and boom.

                   

                  Thanks alot for your time

                  • 6. Re: why wont this script work???
                    Ned Murphy Adobe Community Professional & MVP

                    Your best bet at solving this will be to use the trace function to see what kinds of _x values you are encountering and which values that define them are causing the jumps.