Axonn

Why don't we have .onComplete to a TimeLineLite or Tween object?

Recommended Posts

I suspect that this topic has been approached in the past, but I want to bring my own 2 cents to the table (if you'll have my cents ::- D).

 

Since we can add onComplete and other such callbacks upon construction, why can't we add it later directly in the instance (if we saved the reference to the instance of the TimeLine or Tween).

 

For example, in my situation, I want to add an onComplete to a TimeLine, but only sometimes. It's clumsy to call the constructor in an if statement. I would prefer to call the constructor and append methods and only later add the onComplete event (or any other such events).

 

Are you just saving space in the library? Because as far as I suspect, this would be a piece of cake to make.

 

Could you perhaps advise how to implement this as an extension to your library? I'm thinking of extending the TimeLine class and add the properties myself. Size is not a concern for me (these days, for who is?).

Share this post


Link to post
Share on other sites

Hi Axonn,

 

The max brothers (TweenMax and TimelineMax) support AS3 event dispatching.

 

its totally possible to add eventListeners optionally and at the time of your choosing:

 

import com.greensock.*;
import com.greensock.events.TweenEvent;
var tl:TimelineMax = new TimelineMax();

tl.insert( TweenLite.to( mc3, 1, {x:400, delay:1} ));

tl.addEventListener(TweenEvent.COMPLETE, completeHandler);

function completeHandler(e:TweenEvent):void{
    trace(e.target + " has completed");
}

  • Like 1

Share this post


Link to post
Share on other sites

oh, silly me, you can also do exactly what you want with TimelineLite

 

 

import com.greensock.*;

var tl:TimelineLite = new TimelineLite();

tl.insert( TweenLite.to( mc3, 1, {x:400} ));

tl.vars.onComplete = completeHandler;

function completeHandler():void{
trace("timeline has completed");
}

 

and with TweenLite:

 

import com.greensock.*;
var t:TweenLite =  TweenLite.to( mc3, 1, {x:400} );
t.vars.onComplete = completeHandler;
function completeHandler():void{
trace("tween has completed");
}

  • Like 2

Share this post


Link to post
Share on other sites

Ouchhhhhhhhhhh. I never thought of trying those two! I feel dumb.

 

Thank you carl schooff! ::- D.

 

LATER EDIT:

 

However, it would be nice I guess for TimeLine to have addEventListener as well, for consistency reasons. Do you agree?

Share this post


Link to post
Share on other sites
However, it would be nice I guess for TimeLine to have addEventListener as well, for consistency reasons. Do you agree?

Actually no, for several reasons:

 

1) Callbacks perform much better (faster)

 

2) Adding event dispatching adds kb to the core, but TweenLite is intended to be lightweight and only have the essentials (well, it's actually quite robust as it is, but you know what I mean).

 

3) You can accomplish pretty much everything with callbacks that you can with event listeners. I'm actually inclined to remove event dispatching from TweenMax and TimelineMax now that in v12 there's a way to self-reference the tween instance inside onCompleteParams (and other *Params). I'd like to keep the API slim, so unless there's a very important reason to add a feature/method/property, I try to avoid it. I think ultimately that serves everyone best. I'm not planning to remove event dispatching from TweenMax/TimelineMax yet because backwards compatibility is important to me, so don't worry :)

 

So do you see why it might not be good to add that functionality to TweenLite?

Share this post


Link to post
Share on other sites

Yes. I see. But I'm a big fan of consistency. So then, I would be in favor of removing event dispatching from Tween*.* and let's just all work with .vars.

 

(thanks for joining the talk).

Share this post


Link to post
Share on other sites

is xxx.vars.onComplete carry any event? is the callback example available in As2 too?

thanks

 

Update: Ok I found that adding onComplete:MyFunction,onCompleteParams:["{self}"] it will return the event with its target.

 

thanks

  • Like 1

Share this post


Link to post
Share on other sites

Cool. 

If I recall correctly AS2 did not support official events, they were added in AS3. Its been a very long time ;)

Share this post


Link to post
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.