Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

Reverse on Rollout ?

Recommended Posts

Hi guys, again. This time:


i have five movieclips (with different instance names, but same tween) and i am tweening them with a for loop.


I need each movieclip to make a slight move onrollover (relatively to its position) , while returning back to its original position on onrollout. The way i tried to solve it, was setting exactly the same amount of pixels to the rollout, but with oposite value.


The problem comes when i rollout the movieclip, BEFORE it completes the movement. I have attached a video for you to see it. and here is the code:


for (i=0; i<links_menu.length; i++)
            links_menu.onRollOver = function (){            
            TweenMax.to(this, 1, {_x:"19", _y:"-4.75"})};
            links_menu.onRollOut = function (){            
            TweenMax.to(this, 1, {_x:"-19", _y:"4.75"})};


I also tried this, but didn't worked out, and i don't understund why:


for (i=0; i<links_menu.length; i++)
            links_menu.onRollOver = function (){            
            TweenMax.to(this, 1, {_x:"19", _y:"-4.75"})};
            links_menu.onRollOut = function (){        
            var rolloutx = "this._x"; // rel.position of on rollout
            var rollouty = "this._y"; // rel. position of y on rollout
            TweenMax.to(this, 1, {_x:("this._x")-("this._x"),


// _x = the relative position of x when i roll out minus same number.
// _y = the relative position of y when i roll out minus same number.
//Logically it should work but it doesn't


was wondering if there is such thing as a reverse function on rollout?



Link to comment
Share on other sites

Yup, your video clearly shows the danger of using relative values in certain situations, especially in rollover/rollout handlers.


The code is working exactly as expected. When you pass in a relative value to a tween that value is relative to the object's current position at the time the tween is created. So if you rollover/out very quickly you are going to keep creating new tweens that keep pushing your object further and further away.


In this situation each menu item should have its own tween that is created once in a paused state and then you call play() / reverse() on rollover/rollout respectively:


for (i=0; i<links_menu.length; i++) {
//give each menu item its own tweened and pause it
links_menu[i].tween = TweenLite.to(links_menu[i], 1, {_y:"100", paused:true});
links_menu[i].onRollOver = function (){
links_menu[i].onRollOut = function (){

beware if you move the item you rolling over AWAY from the mouse it will trigger the rollout and things could get a little sketchy.

  • Like 1
Link to comment
Share on other sites

It worked perfectly! :mrgreen:


Thanks so much for taking your the time to help, Carl.


you helped me a lot!

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.