Jump to content
GreenSock

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

TweenMax + play + reverse

Recommended Posts

Hi there- Quick question.

 

I have a simple TweenMax instance that gets created whenever a button is moused over. This Tween is then played or reversed based on the event's current type, for instance:

 

	private var _t:TweenMax
	... code truncated
	private function itemBtn(e:MouseEvent):void {
		_t = new TweenMax(e.currentTarget, 1, {y:40, paused:true});
		if (e.type=="mouseOver") {
			_t.play();
		}
		if (e.type=="mouseOut") {
			_t.reverse();
		}
	}

 

This will play the animation but it seems to ignore the reverse method... can you tell me why? Also, it's imperative that I pass the currentTarget to the TweenMax instance as this currentTarget is the item I'm looking to tween. Thanks, any help is appreciated!

Link to comment
Share on other sites

Hey there- Ok so all I had to do was check whether or not the obj was in the current act of tweening, if not then set the tween. For instance:

 

         private var _t:TweenMax
         ... code truncated
         private function itemBtn(e:MouseEvent):void {
            if (!TweenMax.isTweening(e.currentTarget)) {
               _t = new TweenMax(e.currentTarget, 1, {y:40, paused:true});
            }
            if (e.type=="mouseOver") {
               _t.play();
            }
            if (e.type=="mouseOut") {
               _t.reverse();
            }
         }

Link to comment
Share on other sites

Yep, you got it. Just so others understand, here's an excerpt from the documentation about reversing a tween:

 

This does not swap the starting/ending values in the tween - it literally changes its orientation/direction. Imagine the playhead moving backwards instead of forwards. This does NOT force it to the very end and start playing backwards. It simply affects the orientation of the tween, so if reversed is set to true initially, it will appear not to begin because it is already at the beginning. To cause it to play backwards from the end, set reversed to true and then set the currentProgress property to 1 immediately after creating the tween (or set the currentTime to the duration).
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.
×