Jump to content
Search Community

Writing a function that returns TweenLite Objects?

Bragolgirith test
Moderator Tag

Recommended Posts

Hello friends,

I have a Timeline and am trying to streamline the process of appending Tweens to it.

 

Currently I have:

var myTimeline:TimelineMax = new TimelineMax();
myTimeline.append(new TweenLite(someObject1,1.1,{x:100, y:100, rotation:Math.random()*60-30, onComplete:reinitializeObject, onCompleteParams:[someObject1]}),-0.7);
myTimeline.append(new TweenLite(someObject2,1.1,{x:100, y:100, rotation:Math.random()*60-30, onComplete:reinitializeObject, onCompleteParams:[someObject2]}),-0.7);

, which is working fine.

But is there a way to create the tweens with a reusable function, like this:

var myTimeline:TimelineMax = new TimelineMax();
myTimeline.append(tweenToBottomScreen(someObject1),0.7);
myTimeline.append(tweenToBottomScreen(someObject2),0.7);

function tweenToBottomScreen(cdo:DragObject){
    return new TweenLite(cdo,1.1,{x:100, y:1000, rotation:Math.random()*60-30, onComplete:reinitializeObject, onCompleteParams:[cdo]});
}

so I need only change a single line of code, as opposed to manually editing for every Object.

 

The code above seems to be performing the tween the moment it is created, which messes up the timings.

 

Thank you in advance!

Link to comment
Share on other sites

Sure, that should definitely work - I do that sort of thing all the time. Are you saying that BOTH of your example tweens (for someObject1 and someObject2) are running immediately and concurrently? I can't imagine how/why that would be - you are appending each one separately, so your someObject1 tween would happen first (after the 0.7 second delay you requested in the append()) and then the someObject2 tween after that. If you're not getting the expected behavior, please post a sample FLA that clearly demonstrates the issue so that we can publish it on our end and see what's going on.

Link to comment
Share on other sites

As it often happens, it was an error on my part - I was creating tweens for the same objects in more than one place. I rewrote and simplified that part of the code and it is now working as expected.

 

Sorry for wasting your time and thank you for the wonderful support! :)

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