11 Replies Latest reply on Jan 18, 2013 9:57 AM by ggaarde

    Can not get two AS2 scrollers to work on same page.

    ggaarde Level 1

      Hi.

       

      I really like this particular scroller I used at the bottom of the page here:

      http://steamandclean.com

       

      Now I need to use two instances of it side by side on another page and can not get it to work.

       

      I have tried:

      • Having same code twice in frame 1 unchangend.
      • Having two instances of all the code but with renamed variables and instance names throughout the code.
      • Having each scroller in their own movie clip and then add them both to the scene.
      • Having a master fla with the background and importing two separate swfs with each their own scroller - they work independantly but when they import to the same page one of them will not work.

       

      Here is the AS2 I am using:

       

      Left scroller:

       

       

      fscommand("allowscale", "true");

      bar.useHandCursor = dragger.useHandCursor=false;

      space = 20;

      friction = 0.9;

      speed = 4;

      y = dragger._y;

      top = main._y;

      bottom = main._y+mask_mc._height-main._height-space;

      dragger.onPress = function() {

                drag = true;

                this.startDrag(false, this._x, this._parent.y, this._x, this._parent.y+this._parent.bar._height-this._height);

                scrollEase();

      };

      dragger.onMouseUp = function() {

                this.stopDrag();

                drag = false;

      };

      bar.onPress = function() {

                drag = true;

                if (this._parent._ymouse>this._y+this._height-this._parent.dragger._height) {

                          this._parent.dragger._y = this._parent._ymouse;

                          this._parent.dragger._y = this._y+this._height-this._parent.dragger._height;

                } else {

                          this._parent.dragger._y = this._parent._ymouse;

                }

                scrollEase();

      };

      bar.onMouseUp = function() {

                drag = false;

      };

      moveDragger = function (d) {

                if ((dragger._y == y+bar._height-dragger._height && d == 1) || (dragger._y == y && d == -1)) {

                          clearInterval(myInterval);

                } else {

                          dragger._y += d;

                          scrollEase();

                          updateAfterEvent();

                }

      };

      up_btn.onPress = function() {

                myInterval = setInterval(moveDragger, 18, -1);

      };

      down_btn.onPress = function() {

                myInterval = setInterval(moveDragger, 18, 1);

      };

      up_btn.onMouseUp = down_btn.onMouseUp=function () {

                clearInterval(myInterval);

      };

      MovieClip.prototype.scrollEase = function() {

                dragger.onEnterFrame = function() {

                          if (Math.abs(dy) == 0 && drag == false) {

                                    delete this.onEnterFrame;

                          }

                          r = (this._y-y)/(bar._height-this._height);

                          dy = Math.round((((top-(top-bottom)*r)-main._y)/speed)*friction);

                          main._y += dy;

                };

      };

       

       

      Right scroller

       

      fscommand("allowscale", "true");

      bar2.useHandCursor = dragger2.useHandCursor=false;

      space = 20;

      friction = 0.9;

      speed = 4;

      y = dragger2._y;

      top = main2._y;

      bottom = main2._y+mask_mc._height-main2._height-space;

      dragger2.onPress = function() {

                drag = true;

                this.startDrag(false, this._x, this._parent.y, this._x, this._parent.y+this._parent.bar2._height-this._height);

                scrollEase();

      };

      dragger2.onMouseUp = function() {

                this.stopDrag();

                drag = false;

      };

      bar2.onPress = function() {

                drag = true;

                if (this._parent._ymouse>this._y+this._height-this._parent.dragger2._height) {

                          this._parent.dragger2._y = this._parent._ymouse;

                          this._parent.dragger2._y = this._y+this._height-this._parent.dragger2._height;

                } else {

                          this._parent.dragger2._y = this._parent._ymouse;

                }

                scrollEase();

      };

      bar2.onMouseUp = function() {

                drag = false;

      };

      movedragger2 = function (d) {

                if ((dragger2._y == y+bar2._height-dragger2._height && d == 1) || (dragger2._y == y && d == -1)) {

                          clearInterval(myInterval);

                } else {

                          dragger2._y += d;

                          scrollEase();

                          updateAfterEvent();

                }

      };

      up_btn2.onPress = function() {

                myInterval = setInterval(movedragger2, 18, -1);

      };

      down_btn2.onPress = function() {

                myInterval = setInterval(movedragger2, 18, 1);

      };

      up_btn2.onMouseUp = down_btn2.onMouseUp=function () {

                clearInterval(myInterval);

      };

      MovieClip.prototype.scrollEase = function() {

                dragger2.onEnterFrame = function() {

                          if (Math.abs(dy) == 0 && drag == false) {

                                    delete this.onEnterFrame;

                          }

                          r = (this._y-y)/(bar2._height-this._height);

                          dy = Math.round((((top-(top-bottom)*r)-main2._y)/speed)*friction);

                          main2._y += dy;

                };

      };

       

       

       

      If needed I can upload the fla files, but I see no option to attach a file

       

       

      Thank you on beforehand!

       

      ggaarde

       

       

      Screen shot 2012-11-15 at 12.02.28 PM.png

        • 1. Re: Can not get two AS2 scrollers to work on same page.
          Ned Murphy Adobe Community Professional & MVP

          For the two sets of code you show I can see where there are things that are still not differentiated between the two.  When you created them as separate movieclips did you place the code inside the movieclips?

          • 2. Re: Can not get two AS2 scrollers to work on same page.
            ggaarde Level 1

            Hi Ned!

             

            Thank you for your quick reply.

             

            Yes, I had one set of action script inside each movie clip.

             

            ggaarde

            • 3. Re: Can not get two AS2 scrollers to work on same page.
              Ned Murphy Adobe Community Professional & MVP

              Stick with the two movieclip approach for portability sake and change the very last function into the two functions shown below...

               

              function scrollEase() {
                   dragger.onEnterFrame = dragEase;
              };

               

              function dragEase() {
                if (Math.abs(dy) == 0 && drag == false) {
                    delete dragger.onEnterFrame;
                }
                r = (this._y-y)/(bar._height-this._height);
                dy = Math.round((((top-(top-bottom)*r)-main._y)/speed)*friction);
                main._y += dy;
              };

              1 person found this helpful
              • 4. Re: Can not get two AS2 scrollers to work on same page.
                ggaarde Level 1

                Thank you!

                 

                So your idea is to delete the dragger when the second scroller is activated?

                 

                Would you mind letting me know exactly which part of the code should be replaced?

                And confirm that I should do it in both scripts.

                 

                Do I replace this whole section ?:

                 

                 

                MovieClip.prototype.scrollEase = function() {

                          dragger.onEnterFrame = function() {

                                    if (Math.abs(dy) == 0 && drag == false) {

                                              delete this.onEnterFrame;

                                    }

                                    r = (this._y-y)/(bar._height-this._height);

                                    dy = Math.round((((top-(top-bottom)*r)-main._y)/speed)*friction);

                                    main._y += dy;

                          };

                };

                 

                 

                 

                ggaarde

                • 5. Re: Can not get two AS2 scrollers to work on same page.
                  Ned Murphy Adobe Community Professional & MVP

                  You should only have one set of code, forget the second set you created.  You could even have just one movieclip where you load the "main" portion into it dynamically.  But for the moment I expect you will create one movieclip using your first set of code, replacing the last function....

                   

                  MovieClip.prototype.scrollEase = function() {

                            dragger2.onEnterFrame = function() {

                                      if (Math.abs(dy) == 0 && drag == false) {

                                                delete this.onEnterFrame;

                                      }

                                      r = (this._y-y)/(bar2._height-this._height);

                                      dy = Math.round((((top-(top-bottom)*r)-main2._y)/speed)*friction);

                                      main2._y += dy;

                            };

                  };

                   

                   

                  with what I showed in the last posting.

                   

                  For the second scroller movieclip just create a copy of the first one in the library and only change whatever content goes into the "main" movieclip.

                   

                  Afterwards challenge..... If you want to have just one movieclip that you use for both then you could create the two content sections as movieclips in the library and use the attachMovie function to load each one in to its own scroller.

                  1 person found this helpful
                  • 6. Re: Can not get two AS2 scrollers to work on same page.
                    ggaarde Level 1

                    Thank you so much. I will try your approach and let you know if I can make it work.

                    ggaarde

                    • 7. Re: Can not get two AS2 scrollers to work on same page.
                      ggaarde Level 1

                      Hi Ned

                       

                      I was able to make it work by using my master with importing two swf's. One for each scroller.

                      I used my code with your replacement in both swfs. Then it worked!

                       

                      There may be a simpler way to do it in one file, but this works for now.

                       

                      You are the best!

                       

                      Thank you and have a great day!

                       

                      ggaarde

                      • 9. Re: Can not get two AS2 scrollers to work on same page.
                        ggaarde Level 1

                        Hi Again

                         

                        In a scroller it seems to be impossible to make a link work. Do you have any workaround to make simple text links work inside th  scrollers. ?

                         

                        ggaarde

                        • 10. Re: Can not get two AS2 scrollers to work on same page.
                          Ned Murphy Adobe Community Professional & MVP

                          You should always start a new posting for a new problem (for a few reasons).  That said, how are you implementing the links that they do not work for you?

                          • 11. Re: Can not get two AS2 scrollers to work on same page.
                            ggaarde Level 1

                            Another issue has come about with this page:

                            The draggers in between the arrow heads can be moved beyond (both above and below) the designated area and past the arrowheads if the page is scrolled by the arrowheads. If you drag the dragger by itself it will stay within the boundry (between the arrow heads)

                             

                            I have encountered this before when I have copy/pasted this script from project to project and altered the height of the scroller area.

                             

                            Can you termine what causes it?

                             

                            ggaarde