Jump to content
GreenSock

Applauz

TweenMax Mousewheel

Recommended Posts

I'm trying to set top and bottom limits on a scrolling / tweening movie clip and can't quite get it to work.

 

Here is my current code.  Any help would be appreciated.


var destY:Number = activity_mc.y;



function handleMouseWheel(e:MouseEvent):void {
	
trace(activity_mc.y);
trace(e.delta);	
	

    var _delta:int = e.delta > 0 ? 1 : -1;
    destY += _delta * 200;
    TweenMax.to(activity_mc, .2, {y:destY});
	
    
}

Link to comment
Share on other sites

Sorry, its difficult to trouble shoot partial code fragments like that.

For one I don't see where you are using addEventListener to register that function to respond to MouseEvent.MOUSE_WHEEL.

 

Also, I'd suggest trying to make it work without the tween, just try to find the proper y value first.

 

something like this should work

 

import com.greensock.*;


import flash.events.MouseEvent;


function handleMouseWheel(event:MouseEvent):void {
   


      var newY = mc.y + (event.delta * 3)
//keeps y value of mc between 0 and 300
 newY = constrain(newY, 0, 300);
 TweenLite.to(mc, 1, {y:newY}); 


        trace(mc.y);
        trace(event.delta);


    
}




function constrain(num:Number, min:Number = 0, max:Number = 1):Number
{
if (num < min) return min;
if (num > max) return max;
return num;
}


stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
Link to comment
Share on other sites

Worked out perfectly .. thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×