Jump to content
Search Community

Question about canceling a tween on Click

vdubplate test
Moderator Tag

Recommended Posts

I'm working on a project in as2

 

Basically I have a bar on the stage that houses an ad if you click it the ad opens, if not in 4 seconds the ad goes away and there is a tab that also has a smaller ad that will expand the ad. My problem is even when the bar is clicked the ad opens and then the bar after 4 seconds goes away anyway. Is there a way to have that tween that happens in 4 seconds stop cancel if the bar is clicked so it won't retract?

 

Here is my code: (it looks like a lot but its not that bad)

 

// This will drop the bar after 4 seconds and shrink the button state to the second tab

TweenMax.to(bar_mc, 1, {_y:733, delay:4});

TweenMax.to(button_state_btn, 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});

TweenMax.to(close_bar_btn, 1, {_y:0, delay: 1});

//trace("clicked");

}

Link to comment
Share on other sites

You lots of tools to choose from:

 

You can use TweenLite.killTweensOf(YOUR_OBJECT) to kill all tweens of a particular object.

 

You can kill() individual tweens like myTween.kill(). For example:

var myTween:TweenMax = TweenMax.to(bar_mc, 1, {_y:733, delay:4});
//...then later...
myTween.kill()

 

You could put your code in a function that has conditional logic in it, like:

TweenLite.delayedCall(4, on4SecTimeout);
function on4SecTimeout():Void {
   if (!barIsOpen) {
       //do tweens here...
   }
}

 

Just a few ideas :)

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...