Jump to content
Search Community

Tweening a null object

burvs test
Moderator Tag

Recommended Posts

Something I used to do now and again was tween a null object specifically for the purpose of calling a function after a delay like this:

 

TweenMax.to(null, 3, {onComplete:doStuff});

 

.. which was just a handy way of making "doStuff" happen after 3 seconds. I'm sure it was Jack himself that actually suggested this as a valid way of working (albeit some time ago now).

 

I've noticed that with the latest update, this has stopped working and now throws an error that you can't tween a null object.

 

Is there a way around this, or some other equally handy way of achieving the same thing?

 

Thanks!

Link to comment
Share on other sites

Yep, Carl is exactly right. I'll just add a couple things for clarity:

 

1) I updated the recent version of TweenLite/Max to throw Errors when the target is null because it can help with debugging code. Previously, when developers wrote faulty code that accidentally created tweens of null objects, the runtime errors would occur only when the tween started rendering and applying values to null objects but since the first render typically occurs 1 frame after the tween is created, it wouldn't be immediately clear to the developer WHERE in his/her code the null tween was getting created. The new version forces Flash to choke immediately which can actually be a very helpful thing so that you can track down your faulty code. See what I mean?

 

2) I don't think I ever recommended tweening a null object, but it is perfectly acceptable to use a function or dummy object as the target of your tween like this:

 

TweenLite.to(myFunction, 1, {onComplete:myFunction});
TweenLite.to({}, 1, {onUpdate:myFunction});

 

That's basically what a delayedCall() is anyway - a tween that uses the function as the target, sets an onComplete and immediateRender:false and overwrite:false.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

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