13 Replies Latest reply on Dec 5, 2007 7:39 PM by kglad

    Limiting follow cursor to certain area

    Dave Blake
      I initially posed this question in the general flash forum but decided it might be better suited here. I have a navigation setup in which I want a bar to follow the cursor when the cursor enters the navigation box area itself. (Basically it will follow up and down only. My question is- how do I get the bar to not be affected (i.e., not move unless the cursor is in the navigation area. Right now, the bar follows the mouse up and down whether the mouse cursor is in the navigation area or not

      myInterval = setInterval (moveMask,50);

      function moveMask () {
      Bar._y -= (Bar._y-_ymouse)/5;
      if ( Bar._y >=541){Bar._y=541;}
      if ( Bar._y <= 330){Bar._y=330;}
      if ( Bar._x >=627){Bar._x=627;}
      if ( Bar._x <= 451){Bar._x=451;}
      }

      Navigation.setMask(Bar);

      Thanks,
      Dave
        • 1. Re: Limiting follow cursor to certain area
          kglad Adobe Community Professional & MVP
          use an if-statement to check if the mouse is in the navigation area before updating Bar's _x,_y properties.
          • 2. Re: Limiting follow cursor to certain area
            Dave Blake Level 1
            Sweet! It works. Here's my code:
            myInterval = setInterval (moveMask,50);

            function moveMask () {
            if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 80 && _root._ymouse <= 400) {
            Bar._y -= (Bar._y-_ymouse)/5;
            if ( Bar._y >=318){Bar._y=318;}
            if ( Bar._y <= 110){Bar._y=110;}
            if ( Bar._x >=1000){Bar._x=1000;}
            if ( Bar._x <= 820){Bar._x=820;}
            }
            }

            Navigation.setMask(Bar);

            Okay, lets say I want to tweek it a bit more. With this being a navigation menu and the bar is moving to the menu selection they put the cursor over, how would I get the moving bar to go to an exact location (i.e- exactly on top of the menu item) once the cursor is within a certain vicinity. So even if they don't have the cursor exactly over say, "Home", it would still move the bar exactly over it with the assumption that this is the menu choice they want. Hope this makes sense!

            Thanks,
            Dave
            • 3. Re: Limiting follow cursor to certain area
              Sketchsta
              If i understood correctly, this should do it...

              you can have pre-set variables containing the Bar._x and Bar,_y positions for each item in your menu, then move the menu to the desired _x and _y variable when you want.
              • 4. Re: Limiting follow cursor to certain area
                Dave Blake Level 1
                Okay- I might be getting in over my head a bit here. I am attempting to get the bar to locate at a designated location for the Services menu item. Here is my code but it doesn't work:

                myInterval = setInterval (moveMask,50);

                Services = Bar.y=178;

                function moveMask () {
                if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 80 && _root._ymouse <= 400) {
                Bar._y -= (Bar._y-_ymouse)/5;
                if ( Bar._y >=318){Bar._y=318;}
                if ( Bar._y <= 110){Bar._y=110;}
                if ( Bar._x >=1000){Bar._x=1000;}
                if ( Bar._x <= 820){Bar._x=820;}
                }
                if(_root._xmouse >= 153 && _root._xmouse <= 202)
                {
                Bar.y = ("Services");
                }
                }

                Navigation.setMask(Bar);
                • 5. Re: Limiting follow cursor to certain area
                  kglad Adobe Community Professional & MVP
                  check if the Bar is close to the mouse ( ie, use something like if(Math.abs(Bar._y-_ymouse)<tolerance) ) and a hitTest between the mouse and your buttons to assign the Bar the exact location you want.
                  • 6. Re: Limiting follow cursor to certain area
                    Dave Blake Level 1
                    Uhm...would you be able to give me a basic outline of the coding for this? I'm pretty much new at this and don't have the know-how to impliment your suggestion.

                    Thanks,
                    Dave
                    • 7. Re: Limiting follow cursor to certain area
                      kglad Adobe Community Professional & MVP
                      if you have buttonNum number of buttons with instance names button_0, button_1 etc on the current timeline, you can use:

                      • 8. Re: Limiting follow cursor to certain area
                        Dave Blake Level 1
                        I updated the code with what you provided:

                        myInterval = setInterval (moveMask,50);


                        tl = this;
                        function moveMask() {
                        if (_root._xmouse>=820 && _root._xmouse<=1000 && _root._ymouse>=80 && _root._ymouse<=400) {
                        Bar._y -= (Bar._y-_ymouse)/5;
                        if (Math.abs(Bar._y-_ymouse)<5) {
                        for (var i = 0; i<buttonNum; i++) {
                        if (tl["button_0"+i].hitTest(_xmouse, _ymouse)) {
                        Bar._y = tl["button_0"+i]._y;
                        }
                        }
                        }
                        }
                        }
                        Navigation.setMask(Bar);

                        I have buttons named Button_0, Button_1, Button_2, and Button_3 on the timeline. Is the code you provided for just one button instance? Do I need to fill in values in the code to make it work? Sorry for my ignorance:)

                        Dave
                        • 9. Re: Limiting follow cursor to certain area
                          Dave Blake Level 1
                          Okay-

                          I have it working in this instance in that when it gets to the area of a menu item within the 110 and 140 y parameters, the rolling bar movie clip will go to the specified y location I set up with the variable. (I don't really need to worry about the x coordinates I guess as it only goes up and down. To fine-tune this one more step, is there a way to make the rolling bar gradually go to the y variable coordinate? RIght now, when the cursor gets within the set range, it just abruptly goes to the spot. Here's my code:

                          myInterval = setInterval (moveMask,50);


                          function moveMask () {
                          var hit_X = 820;
                          var hit_Y = 122;
                          if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 80 && _root._ymouse <= 400) {
                          Bar._y -= (Bar._y-_ymouse)/5;
                          if ( Bar._y >=318){Bar._y=318;}
                          if ( Bar._y <= 110){Bar._y=110;}
                          if ( Bar._x >=1000){Bar._x=1000;}
                          if ( Bar._x <= 820){Bar._x=820;}
                          }
                          if(_root._ymouse >= 110 && _root._ymouse <= 140)
                          {
                          Bar._y = hit_Y;
                          }
                          }

                          Navigation.setMask(Bar);

                          Thanks,
                          Dave
                          • 11. Re: Limiting follow cursor to certain area
                            Dave Blake Level 1
                            Sorry I didn't get back sooner but I was gone for the weekend. Anyway, I updated the code but it still abruptly goes to the hit_Y coordinate once it is in the general vacinity. I did have to add a ")" on the "if ( Bar._x <= 820){Bar._x -= (Bar._x-820/5);}" line of code as it gave me a syntax error. Not sure why I didn't have to do it for all of them though.

                            myInterval = setInterval (moveMask,50);


                            function moveMask () {
                            var hit_X = 820;
                            var home_Y = 126;
                            var services_Y = 177;
                            var portfolio_Y = 231;
                            var contact_Y = 290;
                            var male_Y = 344;

                            if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 80 && _root._ymouse <= 450) {
                            Bar._y -= (Bar._y-_ymouse)/5;
                            if ( Bar._y >=318){Bar._y -= (Bar._y-318)/5;}
                            if ( Bar._y <= 110){Bar._y -= (Bar._y-110)/5;}
                            if ( Bar._x >=1000){Bar._x-= (Bar._x-1000)/5;}
                            if ( Bar._x <= 820){Bar._x -= (Bar._x-820/5);}
                            }
                            if(_root._ymouse >= 110 && _root._ymouse <= 140)
                            {
                            Bar._y = home_Y;
                            }
                            }

                            Navigation.setMask(Bar);
                            • 12. Re: Limiting follow cursor to certain area
                              Dave Blake Level 1
                              Hey- just an FYI.. I finally got it to work with this cool MC_tween extention:
                              #include "mc_tween2.as"

                              myInterval = setInterval (moveMask,50);


                              function moveMask () {
                              var home_Y = 126;
                              var services_Y = 177;
                              var portfolio_Y = 231;
                              var contact_Y = 290;
                              var mail_Y = 344;


                              if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 110 && _root._ymouse <= 140)
                              {
                              Bar.ySlideTo(home_Y, 1, "easeoutquad");
                              }
                              if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 165 && _root._ymouse <= 190)
                              {
                              Bar.ySlideTo(services_Y, 1, "easeoutquad");
                              }
                              if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 219 && _root._ymouse <= 245)
                              {
                              Bar.ySlideTo(portfolio_Y, 1, "easeoutquad");
                              }
                              if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 279 && _root._ymouse <= 300)
                              {
                              Bar.ySlideTo(contact_Y, 1, "easeoutquad");
                              }
                              if(_root._xmouse >= 820 && _root._xmouse <= 1000 && _root._ymouse >= 330 && _root._ymouse <= 352)
                              {
                              Bar.ySlideTo(mail_Y, 1, "easeoutquad");
                              }
                              }

                              Navigation.setMask(Bar);

                              Here's the link if anyone is interested:
                              http://hosted.zeh.com.br/mctween/