5 Replies Latest reply on Dec 3, 2009 6:27 AM by Ned Murphy

    Limit movement of movie clip.

    Lord of Limbo

      I have created a movie that contains a movie clip "scroller" that I can move up and down with an "upbutton" and "downbutton". I need to limit the vertical movement of the clip. The clip should not move lower than _y = 0 and no higher than _y = -820.

       

      Can anyone tell me how to do this. Here is the current script:

       

      upbutton.onPress = function() {

      pressing = true;

      movement = -10;

      };

      upbutton.onRelease = function() {

      pressing = false;

      };

      downbutton.onPress = function() {

      pressing = true;

      movement = 10;

      };

      downbutton.onRelease = function() {

      pressing = false;

      };

      _root.onEnterFrame = function() {

      if (pressing == true) {

      scroller._y = scroller._y+movement;

      }

      };

       

      many thanks for any help.

        • 1. Re: Limit movement of movie clip.
          Ned Murphy Adobe Community Professional & MVP

          Change your enterframe function to something along the lines of....

           

          _root.onEnterFrame = function() {

               if (pressing && scroller._y > -820  && scroller._y < 0) {

                    scroller._y = scroller._y+movement;

               }

          }

          1 person found this helpful
          • 2. Re: Limit movement of movie clip.
            Lord of Limbo Level 1

            Hello Nedwebs. Thanks for that. Unfortunately your solution didn't work. However you might be able to help me with this. This script now does half of the job. It limits the upward movement of my "scroller" movie clip. How can I add a second condition in to limit the downward movement?

             

            here's a link to the current swf:

             

            http://www.sandersnicolson.com/Canvas1.swf

             

            Thank you.

             

             

             

            upbutton.onPress = function() {

            pressing = true;

            movement = -10;

            };

            upbutton.onRelease = function() {

            pressing = false;

            };

            downbutton.onPress = function() {

            pressing = true;

            movement = 10;

            };

            downbutton.onRelease = function() {

            pressing = false;

            };

            _root.onEnterFrame = function()  {

            if (pressing == true){

            scroller._y = scroller._y+movement;

            }{

            if (scroller._y <= -175){

            scroller._y = -175;

            }else if (scroller._y >=0){scroller._y = 0}

             

            };

             

            }

            • 3. Re: Limit movement of movie clip.
              Ned Murphy Adobe Community Professional & MVP

              Try replacing your code with the following.  It won't have an enterframe event constantly firing....

               

              upbutton.onPress = function() {
              _root.onEnterFrame = function(){
                if(scroller._y > -175){
                 scroller._y -= 10;
                } else {
                 scroller._y = -175;
                }
              }
              }

               

              downbutton.onPress = function() {
              _root.onEnterFrame = function(){
                if(scroller._y < 0){
                 scroller._y += 10;
                } else {
                 scroller._y = 0;
                }
              }
              }

               

              upbutton.onRelease = downbutton.onRelease = function() {

              delete _root.onEnterFrame;

              };

              1 person found this helpful
              • 4. Re: Limit movement of movie clip.
                Lord of Limbo Level 1

                Many thanks for that help. I've tweaked it slightly but all now working. Once again, many thanks.

                • 5. Re: Limit movement of movie clip.
                  Ned Murphy Adobe Community Professional & MVP

                  You're welcome