20 Replies Latest reply on Aug 11, 2009 12:28 PM by videostart

    moving the position of box with rollover

    videostart Level 1

      I have a flash file that slides the position of a movieclip to 4 different positions with 4 buttons which works great.  I also want to add 2 buttons that when you roll over them, I would like the position of the movie clip to keep sliding to the left and right until you roll off of the button(and stop when it gets to either end of the movieclip.  The code below slides the movie clip when you click them...if that helps.

       

      onClipEvent (load) {
      _x = 0;
      _y = 0;
      spd = 2;
      //this is the scrolling speed, the hight the number the faster it scrolls//
      }
      onClipEvent (enterFrame) {
      _x += (endX-_x)/spd;
      _y += (endY-_y)/spd;
      _root.page1.onRelease = function() {
        endX = 0;
        endY = 0;
      };
      _root.page2.onRelease = function() {
        endX = -220;
        endY = 0;
      };
      _root.page3.onRelease = function() {
        endX = -440;
        endY = 0;
      };
      _root.page4.onRelease = function() {
        endX = -660;
        endY = 0;
      };
      }

       

       

      I have a new buttons started called "test"

      and here is the function I started:

       

      _root.test.onRollover = function() {
       
      };

       

      Any help is very very very much appreciated!!!!

       

      Thanks

        • 1. Re: moving the position of box with rollover
          Ned Murphy Adobe Community Professional & MVP

          I'm not realy clear on the overall goal, or the different between anything moving, so if the clicking is moving the same thing as the rollover would then try assigning the rollOvers to the two most outlying click functions....

           

          _root.page1.onRelease = _root.test.onRollover = function() {
            endX = 0;
            endY = 0;
          };
          _root.page2.onRelease = function() {
            endX = -220;
            endY = 0;
          };
          _root.page3.onRelease = function() {
            endX = -440;
            endY = 0;
          };
          _root.page4.onRelease = _root.test2.onRollover = function() {
            endX = -660;
            endY = 0;
          };

           

          That may not be the solution you're after but it may lead you to specify some more criteria for the functionality that would be needed.

          1 person found this helpful
          • 2. Re: moving the position of box with rollover
            videostart Level 1

            Thanks for the quick response.  The difference is that the four buttons slide the movieclip to specific x/y coordinates. I want there also to be a forward and backward arrow on either side of the movieclip so when you rollover them, the movieclip will keep scrolling until you roll off it (but always stopping at the very end of the movieclip)

            Does that make sense?

             

            In the functions below, it specifies the end x values, so it stops at the value.  The arrows should scroll the movie clip for as long as you rollover it, but stop when you are roll off it, that's why I can't reuse those functions.

            • 3. Re: moving the position of box with rollover
              Ned Murphy Adobe Community Professional & MVP

              Your story just changed in the same telling of it... from:

               

              the movieclip will keep scrolling until you roll off it (but always stopping at the very end of the movieclip)

               

              to:

               

              scroll the movie clip for as long as you rollover it, but stop when you are roll off it,

               

              So if you can clear that up, then there will be hope of my helping you in reaching a solution.

               

              Also, if 0 and -660 are not the "very end(s) of the movieclip", what are?

              • 4. Re: moving the position of box with rollover
                videostart Level 1

                Ok, 3rd attempt, lol:

                 

                 

                The arrows with the rollover will continuously scroll the movie clip

                The 4 buttons with on(release) functions scroll the movieclip to specific xy coordinates.

                 

                I need to know how to do the first one...so what code will continuously move the movieclip

                Instead of moving it to a designated place and stopping.

                • 5. Re: moving the position of box with rollover
                  Ned Murphy Adobe Community Professional & MVP

                  When you use the clickable buttons, do they quickly speed you to the next stopping point (with some amount of easing)?  And is the goal of the rollovers to scroll you down the line in a more gradual manner... kinda slow and easy-like?

                  • 6. Re: moving the position of box with rollover
                    videostart Level 1

                    Yes!  My explaination worked! Exactly what I'm trying to do.

                    Any ideas how to code that?

                    • 7. Re: moving the position of box with rollover
                      Ned Murphy Adobe Community Professional & MVP

                      Actually, your explanation only led me to wonder if what I asked is what you wanted.  I'm still not sure what you want to have happen when you roll off the buttons, but what I'll offer simply stops the movement since that's where you left it.  Maybe you will be able to reason out what you have to change/introduce to add more controls for it.

                       

                      Due to the different modes of enterframe-type motion, my solution takes code off the object and puts it on the timeline (where it's easier to deal with).

                       

                      Here's a link to the modified version of what I could determine you have.  You should be able to adapt it without much difficulty.

                       

                      http://www.nedwebs.com/Flash/AS2_Step_Scroll.fla

                      • 8. Re: moving the position of box with rollover
                        videostart Level 1

                        Wow! that is absoultely perfect!!

                         

                        Out of curiosity, Is there anway to add a scroll bar to that?

                        • 9. Re: moving the position of box with rollover
                          videostart Level 1

                          When you rolloff of the left and right arrows, is there a way for the movie clip to have an ease out motion when it slows down? So it's not a harsh stop?

                          • 10. Re: moving the position of box with rollover
                            Ned Murphy Adobe Community Professional & MVP

                            I'm trying to figure out how to answer you without coming off as sounding like a jerk... so with that in mind, none of what follows is intended to offend...

                             

                            You can do all of the things you would like to do, you just need to understand how what you currently have works and then figure out how to adapt elements of it into the additional features you want.  The key to working with anything is realizing what tools you have available and how to use them.  I didn't have an answer readily available for you... I created that file because I had to solve it as I went--I am not an expert.

                             

                            With the tools you already have working for you, to realize these new features, the only tools I readily see missing are onPress, startDrag(), and stopDrag(), which would apply to making a scrollbar work (a homemade one).  The easing to a stop, you have the makings of that somewhat already in the clicking function.  So see what you can reason out... one step at a time.

                            1 person found this helpful
                            • 11. Re: moving the position of box with rollover
                              videostart Level 1

                              Ok.  I'm looking at the example file you provided.  If you use the right and left arrow buttons the movie clip scrolls fine.  But if you click one of the middle buttons (that jumps the movie clip to a specific coordinate, then the left arrow, the movie clip doesn't stop when it's at the end, but kind of does a jumping loop.

                               

                              Any idea what would be causing this?

                              • 12. Re: moving the position of box with rollover
                                Ned Murphy Adobe Community Professional & MVP

                                Yes, the last line of the moveMC function is the reason for that--it has an error.  Can you see what the problem might be with that last line?  Compare it to the rest of that function.

                                • 13. Re: moving the position of box with rollover
                                  videostart Level 1

                                  Hmmm...the last line says:

                                   

                                  mc._x = endX;  so that's setting the x position of the movieclip to endX?  Not sure what endX is...?

                                   

                                  I was trying to get the rollover to know when the end of the mc was and stop it from moving, but no luck with this code:

                                   

                                  left.onRollOver = function() {

                                       //moveMC(-660,-1);

                                       /*if(_root.mc._x > -672){

                                            moveMC(-660,-1);

                                       }else if(_root.mc._x == -660){

                                        

                                            trace("done")

                                       }

                                       */

                                       }

                                  • 14. Re: moving the position of box with rollover
                                    Ned Murphy Adobe Community Professional & MVP

                                    You're on target with wondering what the heck endX is... if you look at the rest of the functions you might get an idea of what it is.  And then you might get an idea of what it really needs to be in that particular function, especially if you look at the rest of that function.  It is wrong to have endX there, but what should it be?

                                     

                                    Sorry, but I'd rather get you to think rather than hand you answers.

                                    • 15. Re: moving the position of box with rollover
                                      videostart Level 1

                                      Ok, I tried a bunch of values and came up with x instead of endX.   It seems to work, but I have no idea why, lol!  Can you offer an explaination?

                                      • 16. Re: moving the position of box with rollover
                                        Ned Murphy Adobe Community Professional & MVP

                                        Nope.  I've no idea what x is.  Instead of x the value should be the same as the one passed into that function.... "end"

                                        1 person found this helpful
                                        • 17. Re: moving the position of box with rollover
                                          videostart Level 1

                                          Ok, If I post another example file that I'm working on, would you be able to help me work through it?  I'm not looking for an handout, it would be nice to learn how to code better.

                                          • 18. Re: moving the position of box with rollover
                                            Ned Murphy Adobe Community Professional & MVP

                                            I  can't promise anything.  I have a lineup of things to do that will keep me away from these forums for awhile, but if you post a problem, someone is likely to pick up on it and help if they can.  Your best bet for getting help is to come with a problem that shows you are trying something and it is isn't working.

                                             

                                            Folks that help here don't get paid for it, but many do this kind of work for a living as freelancers... so when it starts to look like a one-sided effort, doing someone's work for them, which can often become readily evident with the initial posting, it's not unusual to see someone left hanging with no one wanting to help other than to suggest searching the web.

                                            • 19. Re: moving the position of box with rollover
                                              videostart Level 1

                                              no worries.....I really like the way my file works now.  i have another file with really nice easing to it that contains the code below. what I'm trying to figure out is if I can add that easing into the file you helped me with or would it be easier to modify the code below into a horizontal scroller like I need.

                                              either way, i'm looking for suggestions on a starting point so I can work on getting this figured out.

                                              I appreciate the help!

                                               

                                               

                                              fscommand("allowscale", "false");
                                              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;

                                               

                                              ///////////no x y values ////////////////////////

                                              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);
                                              };
                                              dragger.onMouseUp = function() {
                                              this.stopDrag();
                                              drag = false;
                                              };
                                              bar.onMouseUp = function() {
                                              drag = false;
                                              };

                                              ///////////no x y values ////////////////////////

                                              dragger.onPress = function() {
                                              drag = true;
                                              this.startDrag(false, this._x, this._parent.y, this._x, this._parent.y+this._parent.bar._height-this._height);
                                              dragger.scrollEase();
                                              };

                                              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;
                                              }
                                              dragger.scrollEase();
                                              };

                                              moveDragger = function (d) {
                                              if ((dragger._y>=y+bar._height-dragger._height && d == 1) || (dragger._y<=y && d == -1)) {
                                                clearInterval(myInterval);
                                              } else {
                                                dragger._y += d;
                                                dragger.scrollEase();
                                                updateAfterEvent();
                                              }
                                              };

                                              MovieClip.prototype.scrollEase = function() {
                                              this.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;
                                              };
                                              };

                                              • 20. Re: moving the position of box with rollover
                                                videostart Level 1

                                                For your example, when I replace your movie clip with my movieclip, it seems to get cut off like there is a mask.

                                                I can't seem to move it around on the stage either.  Do you set the position somewhere?

                                                I couldn't find if you did?