Jump to content
Search Community

StaggerTo() on a Timeline Not Working

Anderson Smith test
Moderator Tag

Recommended Posts

Hi, I am having a problem with staggerTo() working inside a timeline.  Here is my code:

var objects:Array = new Array();
function getObjects():void
{
   objects = [object1, object2, object3];
}
var timeline:TimelineLite = new TimelineLite();
timeline.call(getObjects);
timeline.staggerTo(objects, 1, {scale:0}, 0);

The getObjects() function, which populates the objects array, gets called before I apply staggerTo() on the objects.  However, I think all of the timeline code gets parsed before any of this happens.  So when staggerTo() gets parsed the objects array is actually empty, and the animation doesn't happen.  Is there any way around this?

Link to comment
Share on other sites

Hmm, I thought you posted earlier that you figured it out, but yes your assertion is correct the call() doesn't happen until the timeline plays but the staggerTo attempts to create tweens when the timeline is being built.

 

You can verify this by adding the following trace

 

var timeline:TimelineLite = new TimelineLite();
timeline.call(getObjects);
trace("objects = " + objects) // nothing
timeline.staggerTo(objects, 1, {scale:0}, 0)

 

Its all about order of operations. You can not add the staggerTo() to your timeline until the objects Array is built.

Typically I would hold off on building the timeline until all the targets exist, so I would just call getObjects() outside the timeline. Perhaps if you explained why you are building the timeline first we can offer a better solution. Right now if you need to grab the objects using a call() when the timeline is run the only thing I can suggest is that you use an additional function to add the stagger after getObjects();

 

import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([ScalePlugin]);


var objects:Array = new Array();
function getObjects():void
{
   objects = [object1, object2, object3];
}
var timeline:TimelineLite = new TimelineLite();
timeline.call(getObjects);
trace("objects = " + objects);
timeline.call(addStagger);

function addStagger(){
  timeline.staggerTo(objects, 1, {scale:0}, 0.2, timeline.time())
}
Also to note, if you are using scale you need the ScalePlugin to be activated (see my code above).
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...