Share Posted June 28, 2013 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"), _y:("this._y")-("this._y"))})}; }; // _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? mov.zip Link to comment Share on other sites More sharing options...
Share Posted June 28, 2013 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 (){ this.tween.play(); } links_menu[i].onRollOut = function (){ this.tween.reverse(); } } 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. 1 Link to comment Share on other sites More sharing options...
Author Share Posted June 28, 2013 It worked perfectly! Thanks so much for taking your the time to help, Carl. you helped me a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now