Jump to content
Search Community

Using staggerFromTo referencing MC original position

rob_v_5712 test
Moderator Tag

Recommended Posts

Hello all,

I have been experimenting using the staggerFromTo method in my timelines and was curious if there was a way I can reference an MCs starting point in the from/to part of the tween.

 

For example, I have several figures in various positions on the stage.  

I want to tween these figures in from the left side and I set up a timeline to do it.

The other caveat is, when this timeline runs, I want to MCs to always start the tweens from their original positions, regardless of what happens them while the swf is running.

 

I currently handle it like this.

On the start, I have an object that stores the initial x & y of the MCs on the stage.

(lets call it xyObject)

I then have my timeline :

myTimeline = new TimelineLite( {useFrames:true} );
myTimeline.add("start", 15)
.fromTo(fig_0,30,{x:xy.fig_0.x - 100, alpha:0},{x:xy.fig_0.x, alpha:1}, 25)
.fromTo(fig_1,30,{x:xy.fig_1.x - 100, alpha:0},{x:xy.fig_1.x, alpha:1}, 30)
.fromTo(fig_2,30,{x:xy.fig_2.x - 100, alpha:0},{x:xy.fig_2.x, alpha:1}, 35);

This works fine.  But there are sometimes when Im dealing w/ a lot of MCs, and having them all in an array just makes thing easier.

 

Is there a way I can do something like this using the staggerFromTo method?

 

Thanks in advance

-Rob

Link to comment
Share on other sites

When using staggerTo(), staggerFrom(), and staggerFromTo() all of the tweens that are generated use the same starting and ending values (which is why they are so convenient). If each target of each tween has unique starting and/or ending values, then these methods are not the right tool for the job.

 

I would suggest you use a loop.

 


var mcs:Array = [mc0, mc1, mc2];
var endValues:Array = [100, 200, 350];
var staggerAmount:Number = 0.3;
var tl = new TimelineLite();




for (var i:int = 0; i < mcs.length; i++){
tl.to(mcs[i], 1, {x:endValues[i]}, i * staggerAmount)
}


/*the code above will generate a timeline like this:
tl.to(mc0, 1, {x:100}, 0)
tl.to(mc1, 1, {x:200}, 0.3)
tl.to(mc2, 1, {x:350}, 0.6)

//each tween has a custom end value but the start times are evenly staggered
*/

CS5 fla attached

 

 

loopStagger_CS5.zip

  • Like 1
Link to comment
Share on other sites

Thanks for getting back to me Carl.

 

One more question - is there a way to tween them all from/to distance relative to their starting point?

 

ie - if the MCs were at x= 100,200,300

and I want to tween them all from (their current position -100), to their current position.

(so start them all off at X-100 and tween them all to X )

 

I tried something like this  but cant seem to figure out how to get them back to their initial X

.staggerFromTo(mcArray,30,{x:"-=100", alpha:0},{x:"+=0",alpha:1},5, 45)

If I change the "To" x to +=300 , that seems to do it.  I guess I'm wondering what is going on when I use the += syntax in that situation.

 

Thanks

Link to comment
Share on other sites

The trouble there is that the TO values are relative to the FROM values, not the target's current location.

 

Think of it this way, each mc gets moved -=100 along the x axis to a NEW position when the tween is created. Then you are saying to move to +=0 from that new location (which represents no change at all).

 

Unless I'm misunderstanding you, I think just a staggerFrom will work:

.staggerFrom(mcArray,30,{x:"-=100", alpha:0}, 5, 45)
  • Like 1
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...