3 Replies Latest reply on Oct 29, 2009 7:21 AM by Ned Murphy

    how to focus on mouse position when zooming movie clip using mouse wheel.

    xxxheeroxxx

      I have a map application that when I use the mouse wheel the map will scale up or scale down. The next thing I want to do is to focus on the mouse pointer while zooming on the part of the map.

       

      I have this code...

       

       

      function focusMousePosition(){
          onMouseMove = function (){
              Stage.width = _root._xmouse;
              Stage.height = _root._ymouse;
              updateAfterEvent();
          }
      }

       

      var mouseWheelListener = new Object();
      var wheelNum:Number;

       

      mouseWheelListener.onMouseWheel = function(wheelNum){
          focusMousePosition();
          if (wheelNum > 0){
              map._xscale *= 0.9;
              map._yscale *= 0.9;
          }else{
              map._xscale *= 1.1;
              map._yscale *= 1.1;
          }
      }
      Mouse.addListener(mouseWheelListener);

        • 1. Re: how to focus on mouse position when zooming movie clip using mouse wheel.
          Ned Murphy Adobe Community Professional & MVP

          I don't have a solution to offer, just some thoughts/considerations.  When you zoom/scale objects the scaling occurs relative to the registration axis of the object.  So if you are not pointing at that axis, the point you are on will move away from the mouse.

           

          Since you cannot change the registration axis of the object dynamically, you end up having to use a secondary container object to provide the registration axis that you zoom.  The contained map is moved such that the desired point on the map aligns with the containers registration axis, so while you zoom the container it appears the map is being zoomed at the desired location.

           

          Your goal adds a new twist to this scenario because your description would mean moving the registration axis of the container to where the mouse is... which means moving the map within the container to counter that and appear not to be moving at all.

           

          When you get this far along into the rabbit hole, I start thinking of things like having to utilize the instantaneous _xmouse/_ymouse properties of each of the participating objects and the stage as well to determine how to move the parent while the child remains visually unmoved. Or maybe the key lies in having yet a third containing object?  It's a head scratcher for me at the moment, but maybe someone else had dealt with this before and can offer better direction.

          1 person found this helpful
          • 2. Re: how to focus on mouse position when zooming movie clip using mouse wheel.
            xxxheeroxxx Level 1

            Thank you so much for your reply Mr. Murphy. As you explain in your reply some uncleared idea that I was suffering are now being cleared. But still this would be a head scratching application. I hope I will not get bald because of this hehe.

             

            Thanks a lot for the idea...

             

            One more thing, is there a way to limit the scale of the map?

             

            I came up to this code that if the scale of the map base on map._xscale is not yet equal to 300 the user still can continue to scale up the map. Second is to trap, if the map has been scaled back to its size on the stage and that the user can no longer scale down the map.

             

             

            I have this code but it does'nt work:

             

             

            mouseWheelListener.onMouseWheel = function(wheelNum){
                //focusMousePosition();
                if (wheelNum > 0){
                    scaleAmountB = 0.9;
                    if (map._xscale != 300){
                       
                        map._xscale *= scaleAmountB;
                        map._yscale *= scaleAmountB;
                        /*trace("mouseWheel value = " + wheelNum);
                        trace("realtime x scale = " + map._xscale);
                        trace("realtime y scale = " + map._yscale);*/
                    }else{
                        scaleAmountB = 0;
                        map._xscale *= scaleAmountB;
                        map._yscale *= scaleAmountB;
                    }
                }else{
                    scaleAmountS = 1.1;
                    if (map._xscale != 100){

             

                        map._xscale *= scaleAmountS;
                        map._yscale *= scaleAmountS;
                        /*trace("mouseWheel value = " + wheelNum);
                        trace("realtime x scale = " + map._xscale);
                        trace("realtime y scale = " + map._yscale);*/
                    }else{
                        map._xscale = 100;
                        map._yscale = 100;
                    }
                }
            }
            Mouse.addListener(mouseWheelListener);

            • 3. Re: how to focus on mouse position when zooming movie clip using mouse wheel.
              Ned Murphy Adobe Community Professional & MVP

              You don't want to use != as your limit control because it is unlikely that you will ever equal that value exactly, especially since you are mutliplying by a fractional value.  If you want to set an upper limit use < upper limit, and if you want to set a lower limit use > lower limit.

              1 person found this helpful