Mouse Wheel ZOOM???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paulcybulski
    New Member
    • Nov 2007
    • 25

    Mouse Wheel ZOOM???

    Hi I would like to apply a zoom feature where the user can scroll the mouse wheel to zoom in and out on a movieclip. I currently have zoom implemented as buttons. How would I go about implementing the wheel action?


    button zoom code:

    [AS]
    small.onPress = function(){
    ROOT.onEnterFra me = function(){
    zoom._xscale*=0 .9;
    zoom._yscale*=0 .9;
    checkBounds(0,0 ,0,0);
    }
    }

    small.onRelease = function() {
    delete ROOT.onEnterFra me;
    }

    small.onRelease Outside = function() {
    delete ROOT.onEnterFra me;
    }

    big.onPress = function(){
    ROOT.onEnterFra me = function(){
    zoom._xscale*=1 .1;
    zoom._yscale*=1 .1;
    checkBounds(0,0 ,0,0);
    }
    }

    big.onRelease = function() {
    delete ROOT.onEnterFra me;
    }

    big.onReleaseOu tside = function() {
    delete ROOT.onEnterFra me;
    }
    [/AS]
  • paulcybulski
    New Member
    • Nov 2007
    • 25

    #2
    Ok I figured out the mouse zoom in out thing, but I cannot get the zoom to stop when I use the mouse wheel, with one slight movement of the mouse wheel in either direction, the mc begins to zoom without end...any ideas? Here is the code I have for the mousewheel...

    [AS]
    mouseWheelListe ner = new Object();
    mouseWheelListe ner.onMouseWhee l = function(delta) {
    if(delta > 0){
    ROOT.onEnterFra me = function(){
    zoom._xscale*=0 .9;
    zoom._yscale*=0 .9;
    checkBounds(0,0 ,0,0);
    }
    }else{
    ROOT.onEnterFra me = function(){
    zoom._xscale*=1 .1;
    zoom._yscale*=1 .1;
    checkBounds(0,0 ,0,0);
    }
    }
    }
    Mouse.addListen er(mouseWheelLi stener);
    [/AS]

    Comment

    • rsdev
      New Member
      • Jul 2007
      • 149

      #3
      Originally posted by paulcybulski
      Ok I figured out the mouse zoom in out thing, but I cannot get the zoom to stop when I use the mouse wheel, with one slight movement of the mouse wheel in either direction, the mc begins to zoom without end...any ideas? Here is the code I have for the mousewheel...

      [AS]
      mouseWheelListe ner = new Object();
      mouseWheelListe ner.onMouseWhee l = function(delta) {
      if(delta > 0){
      ROOT.onEnterFra me = function(){
      zoom._xscale*=0 .9;
      zoom._yscale*=0 .9;
      checkBounds(0,0 ,0,0);
      }
      }else{
      ROOT.onEnterFra me = function(){
      zoom._xscale*=1 .1;
      zoom._yscale*=1 .1;
      checkBounds(0,0 ,0,0);
      }
      }
      }
      Mouse.addListen er(mouseWheelLi stener);
      [/AS]
      You have a checkBounds function so if you getBounds in the checkBounds and then switch a Boolean to false to stop the enlargement.

      Example;

      Code:
       mouseWheelListener = new Object(); 
      var scale:Boolean = true;
      mouseWheelListener.onMouseWheel = function(delta) { 
      if(delta > 0){ 
      ROOT.onEnterFrame = function(){ 
      if(scale){
      zoom._xscale*=0.9; 
      zoom._yscale*=0.9;
      } 
      scale = checkBounds(0,0,0,0, _root.[scrollTarget]); //scrollTarget is the mc name in string form so find a way to convert it to an mc
      } 
       
      var maxBounds:Array = new Array({yMax:2000, yMin:-50, xMax:300, xMin:-500})
      function checkBounds(0,0,0,0, mc:MovieClip):Boolean{
      var bounds_obj:Object = mc.getBounds(this);
      for (var i in bounds_obj) {
      	 trace(i+" --> "+bounds_obj[i]);//for debugging
      	 switch(i){
      	 case yMax:
      		if(bounds_obj[i]>maxBounds[0].yMax) return false;
      break;
      	 case yMin:
      		if(bounds_obj[i]<maxBounds[0].yMin) return false;
      break;
      case xMax:
      	 if(bounds_obj[i]>maxBounds[0].xMax) return false;
      break;
      case xMin:
      	if(bounds_obj[i]<maxBounds[0].xMin) return false;
      break;
      }
      }
       
      //add your code here....
       
      return true;
      }
      This is untested!

      Comment

      • paulcybulski
        New Member
        • Nov 2007
        • 25

        #4
        working mousewheel zoom code:

        [AS]
        //--------------------------------- code MouseWheel zoom feature -----------------------\
        var mouseListener:O bject = new Object();
        mouseListener.o nMouseWheel = function(delta)
        {
        if(delta > 0)
        {
        zoom._xscale *= 1.1;
        zoom._yscale *= 1.1;
        }
        else
        {
        if(mc_scale < zoom._xscale)
        {
        zoom._xscale*=0 .9;
        zoom._yscale*=0 .9;
        }
        if(mc_scale >= zoom._xscale)
        {
        _global.contain er._x = mc_X;
        _global.contain er._y = mc_Y;
        }
        }
        }
        Mouse.addListen er(mouseListene r);
        //--------------------------------- end MouseWheel zoom code -----------------------\
        [/AS]

        Comment

        • rsdev
          New Member
          • Jul 2007
          • 149

          #5
          Originally posted by paulcybulski
          working mousewheel zoom code:

          [AS]
          //--------------------------------- code MouseWheel zoom feature -----------------------\
          var mouseListener:O bject = new Object();
          mouseListener.o nMouseWheel = function(delta)
          {
          if(delta > 0)
          {
          zoom._xscale *= 1.1;
          zoom._yscale *= 1.1;
          }
          else
          {
          if(mc_scale < zoom._xscale)
          {
          zoom._xscale*=0 .9;
          zoom._yscale*=0 .9;
          }
          if(mc_scale >= zoom._xscale)
          {
          _global.contain er._x = mc_X;
          _global.contain er._y = mc_Y;
          }
          }
          }
          Mouse.addListen er(mouseListene r);
          //--------------------------------- end MouseWheel zoom code -----------------------\
          [/AS]
          Well done for getting it working. I can see you weren't impressed by my suggestion of checking the mc size against a limit.

          Opting for a scale limit instead.

          Comment

          Working...