Jump to content
Search Community

Newbie: Stop and Clear a tween [SOLVED]

andrex test
Moderator Tag

Recommended Posts

Hi there,

i'm playing with those cool classes but i cannot understand how to stop a tween and how to reset the value (to bring all the mc's to the starting point).

i wrote down a stupid code but it doesn't work... for sure i'm missing something but i cannot understand what...

 

///IMPORT what i need for my test

import gs.TweenMax;

import gs.plugins.*;

import gs.*;

TweenPlugin.activate([blurFilterPlugin, DropShadowFilterPlugin, TintPlugin]);

import gs.easing.*;

 

//want to call a tween as a group to move some mc's

function prova()

{

var tween1:TweenMax = new TweenMax(scheda01red, 2, {_x:"100", ease:Quint.easeOut, startAt:{_x:-100}, blurFilter:{blurX:6, blurY:3}});

var tween2:TweenLite = new TweenLite(scheda02red, 2, {_x:"100", ease:Quint.easeOut, stagger:0.3, blurFilter:{blurX:6, blurY:3}});

var tween3:TweenLite = new TweenLite(scheda03red, 2, {_x:"100", ease:Quint.easeOut, stagger:0.3, blurFilter:{blurX:6, blurY:3}});

GroupSchede = new TweenGroup([tween1, tween2, tween3]);

GroupSchede.align = TweenGroup.ALIGN_SEQUENCE;

}

//a function to try the "stop" and others...

function stoppa()

{

GroupSchede.stop();

//GroupSchede.reverse()

//trace( myTween.duration);

//killTweensOf(GroupSchede);

//removeTween(GroupSchede);

 

 

}

//on Release on this button i call prova and mc's start moving

plei.onRelease = prova;

 

//on Release of this...nothing happen

stop_btn.onRelease = stoppa;

Link to comment
Share on other sites

First off, I'd highly recommend upgrading to v11 of the tweening platform because there are a bunch of new features and tools that will make this easier. There are two new classes (TimelineLite and TimelineMax) that will replace TweenGroup because they're much easier to work with, and they're more powerful and flexible. Get the code and read up on everything at http://blog.greensock.com/v11beta/. I just didn't want you getting used to TweenGroup and then having to switch over when v11 launches (soon).

 

Also, TweenMax automatically activates a whole bunch of plugins by default internally, so you don't need those activation lines you had in your code.

 

Here's what it would look like with v11 code:

 

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

//create a TimelineLite to hold your tweens and pause it initially (TimelineLite and TimelineMax replace TweenGroup in v11)
var myTimeline:TimelineLite = new TimelineLite({paused:true});
myTimeline.append( new TweenMax(scheda01red, 2, {_x:"100", ease:Quint.easeOut, startAt:{_x:-100}, blurFilter:{blurX:6, blurY:3}}) );
myTimeline.append( new TweenLite(scheda02red, 2, {_x:"100", ease:Quint.easeOut, delay:0.3, blurFilter:{blurX:6, blurY:3}}) );
myTimeline.append( new TweenLite(scheda03red, 2, {_x:"100", ease:Quint.easeOut, delay:0.3, blurFilter:{blurX:6, blurY:3}}) );

function prova():Void {
       myTimeline.invalidate(); //only invalidate() if you want to kill the starting values that were recorded when the tweens started, and make them re-initialize.
myTimeline.play();
}

function stoppa():Void  {
myTimeline.stop();
//myTimeline.reverse(); //use this if you prefer to reverse the whole group anytime smoothly
}

plei.onRelease = prova;
stop_btn.onRelease = stoppa;

 

If you want to restart the timeline, just call myTimeline.restart() or set the "currentTime" property to 0. You can also change the timeScale property if you want to speed up or slow down the whole group. TONS of options. There's full ASDoc documentation at http://www.greensock.com/as/docs/tween/. Have fun!

Link to comment
Share on other sites

i'm fallowing the code you wrote down and

i'm tryin your new class playing with:

myTimeline.gotoAndStop();

 

it seems that... if i write

myTimeline.gotoAndStop();//it brings my tween instantly to the end

 

myTimeline.gotoAndStop(0);//after my tween have played if i call it, it brings my tween instantly to the starting point

 

 

myTimeline.gotoAndStop(x);////it brings my tween instantly in different part of the tween (the half point using "1", the 3/4 using "3"...)

 

can you explain me better this, i cannot find this in the on the DOC :oops::oops:

 

THAAAAAAANK YOU!!!

Link to comment
Share on other sites

gotoAndStop() makes the timeline go to a specific time (or label) and then pauses it.

 

//this isn't valid because you're not passing a time or label to the function!
myTimeline.gotoAndStop();

//this will go to the very beginning (a time of zero)
myTimeline.gotoAndStop(0);

//this will go to exactly 5-seconds into the timeline
myTimeline.gotoAndStop(5);

//this will go to wherever the "myLabel" is on the timeline (assuming you used myTimeline.addLabel() to add it) and stop
myTimeline.gotoAndStop("myLabel");

 

Make sense now? It allows you to skip to any point on the timeline.

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