Jump to content
Search Community

Help toggling between a tween [SOLVED]

vdubplate test
Moderator Tag

Recommended Posts

I was wondering if someone could help me out.

 

I have a button that opens an ad unit.

I need the button to close the ad as well.

 

So say this is my code:

 

import com.greensock.*;

import com.greensock.easing.*;

 

button_btn.onPress = function(){

TweenMax.to(test_mc, 1, {_x:462});

}

 

How would I be able to tween this back to say:

TweenMax.to(test_mc, 1, {_x:10});

 

Thanks for the help. i know I've been blowing up the forums lately with questions.

Link to comment
Share on other sites

There are a lot of ways you could do it. Here's one way:

 

var open:Boolean = false; //just tracks whether or not it's open.
button_btn.onPress = function():Void {
   if (open) {
       TweenMax(test_mc, 1, {_x:10});
       open = false;
   } else {
       TweenMax(test_mc, 1, {_x:462});
       open = true;
   }
}

 

Or you could just create one tween and play()/reverse() it like this:

 

var openTween:TweenMax = new TweenMax(test_mc, 1, {_x:462, paused:true});
button_btn.onPress = function():Void {
   if (openTween.reversed) {
       openTween.play();
   } else {
       openTween.reverse();
   }
}

Link to comment
Share on other sites

Ok, so I'm still having issues with this working. I have 2 questions with the second option you showed me.

can i do something like this? So that i can add more than one tween to reverse?

 

var openTween:TweenMax = new TweenMax
(mask_mc, 1, {_y:0, _yscale:0, paused:true});
TweenMax.to(close_bar_btn, 1, {_y:0, delay: 1}); 

button_state_btn.onPress = function():Void {
   if (openTween.reversed) {
       openTween.play();
   } else {
       openTween.reverse();
   }
}

 

 

And here is my code and I can't get it to work. It looks like a lot but I'm only trying to get the mask that I labeled for you to retract.

 

import com.greensock.*;
import com.greensock.easing.*;

var openTween:TweenMax = new TweenMax.to(mask_mc, 1, {_y:0, _yscale:1501, paused:true});
button_state_btn.onPress = function():Void {
   if (openTween.reversed) {
       openTween.play();
   } else {
       openTween.reverse();
   }
}

TweenMax.to(button_state_btn, 1, {_xscale:20, _x:405, _yscale:22, _y:708, delay:4});
TweenMax.to(bar_mc, 1, {_y:733, delay:4});

// This is the code to open and close the bar
button_state_btn.onPress = function() {
TweenMax.to(word_mark, 1, {_alpha:100, delay:2});
TweenMax.to(logo, 1, {_x:518, _alpha:100, delay: 2});
TweenMax.to(spots_container.spots3, 30, {_y:150, repeat:-1, ease:Linear.easeNone, _alpha:100})
TweenMax.to(spots_container.spots2, 30, {_y:150, repeat:-1, ease:Linear.easeNone, delay:9, _alpha:100})
TweenMax.to(spots_container.spots1, 28, {_y:150, repeat:-1, ease:Linear.easeNone, _alpha:100})
// Above tweens spots
TweenMax.to(mask_mc, 1, {_y:0, _yscale:1501}); /////////////////////////////////MASK///////////////////////////////
TweenMax.to(close_bar_btn, 1, {_y:0, delay: 1}); 
//trace("clicked");
}

close_bar_btn.onPress = function() {
TweenMax.to(logo, 1, {_alpha:0, _x:563});
TweenMax.to(word_mark, 1, {_alpha:0});
TweenMax.to(mask_mc, 1, {_y:733, _yscale:0, delay: 1}); 
TweenMax.to(close_bar_btn, 1, {_y:-44, delay: 0});
//spots1._visible = false; spots2._visible = false; spots3._visible = false; 
TweenMax.to(spots1, 1, {_alpha:0});
TweenMax.to(spots2, 1, {_alpha:0});
TweenMax.to(spots3, 1, {_alpha:0});
//trace("clicked");
}

Link to comment
Share on other sites

I think you'd benefit a lot from looking at TimelineLite/Max. There's a video at http://blog.greensock.com/timeline-basics/. It allows you to group/sequence tweens easily and then control them as a whole. So to your first question, you'd use it like this:

 

var openTimeline:TimelineLite = new TimelineLite({paused:true});
openTimeline.append( new TweenMax(mask_mc, 1, {_y:0, _yscale:0}) );
openTimeline.append( new TweenMax(close_bar_btn, 1, {_y:0}) );

button_state_btn.onPress = function():Void {
   if (openTimeline.reversed) {
       openTimeline.play();
   } else {
       openTimeline.reverse();
   }
}

 

The code you posted had two different button_state_btn.onPress defined - that's a problem :)

 

Go watch the video and I think you'll get some ideas about how to organize your tweens and control them. Let us know if you're still having trouble after that.

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.
×
×
  • Create New...