Jump to content
Search Community

How to reuse tweens [SOLVED]

fs_tigre test
Moderator Tag

Recommended Posts

Hi,

 

Excuse my ignorance but what would be the best way to reuse my tweens? In other words I have some tweens and I would like to apply them to multiple movieClips (mc1, mc2, mc3, mc4...) without having to re-write my tweens over and over.

 

I know this is more of an actionscript question but if someone can halp me to minimize the amount of code it would be great.

 

 

TweenLite.to(mc1, .8, {x:300});
TweenLite.to(mc1, 1, {delay:.8, scaleX:2,scaleY:2,overwrite:0});
TweenLite.to(mc1, 1, {delay:2.1, scaleX:1,scaleY:1,overwrite:0});
TweenLite.to(mc1, .8, {delay:2.9, x:560,overwrite:0});
TweenMax.to(mc1, .1, {delay:1.6, glowFilter:{color:0x91e600,alpha:1, blurX:5,
                                    blurY:5,strength:10},remove:true,overwrite:0});

 

I would like to use this set of tweens for mc2, mc3 etc.

 

Thanks

Link to comment
Share on other sites

I'd recommend creating a function that does it for you and you simply pass in the mc as a variable. You could even create the sequence in a TimelineLite instance so that you could control the entire thing as a whole for each mc. Like:

 

function buildAnimation(mc:DisplayObject):TimelineLite {
   var timeline:TimelineLite = new TimelineLite();
   timeline.append( TweenLite.to(mc1, .8, {x:300}) );
   timeline.append( TweenLite.to(mc, 1, {scaleX:2, scaleY:2}) );
   timeline.append( TweenLite.to(mc, 1, {scaleX:1,scaleY:1}), 0.3);
   timeline.append( TweenLite.to(mc, .8, {x:560}), -0.2);
   timeline.insert( TweenMax.to(mc, .1, {glowFilter:{color:0x91e600, alpha:1, blurX:5, blurY:5, strength:10, remove:true}}), 1.6);
   return timeline;
}

 

Then, to create the same animation sequence for mc1, mc2, and mc3, you'd do:

 

var t1:TimelineLite = buildAnimation(mc1);
var t2:TimelineLite = buildAnimation(mc2);
var t3:TimelineLite = buildAnimation(mc3);

 

And then you can easily control each sequence as a whole like t1.pause(), t1.resume(), t1.reverse(), t1.play(), or t1.restart().

 

If you're not familiar with TimelineLite, you can read more at

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