Jump to content
Search Community

Dummy TweenMax just for onUpdate?

BladePoint test
Moderator Tag

Recommended Posts

I've been using a dummy Tweenmax just so I can use its onUpdate. 

var dummyPoint:Point = new Point(0,0);
//This only purpose of this point is to give TweenMax something with a property to tween.

TweenMax.to(dummyPoint, 10, {x:1, repeat:-1, onUpdate:myFunction});
function myFunction():void {
     //This is the function that I would like to be called repeatedly.
}

The other ways that I've tried to continually repeat my function just end in an infinite loop error. With the dummy TweenMax, I don't get that and I can kill it whenever I want to. Is there a more elegant way to do this?

Link to comment
Share on other sites

If that works, I'd stick with it, but here is another option:

 

Create a repeating TimelineMax that is 1 frame long and has a callback on frame 1 like so:

 

var tl = new TimelineMax({repeat:-1, useFrames:true})
tl.call(myFunction, [], this, 1)

function myFunction(){
  console.log("running")
}
 
Open up the console on this: http://codepen.io/anon/pen/uxlkf
 
the only thing that makes this slightly more elegant is that you aren't tweening something that doesn't need to be tweened.
I am doubtful though that my way will run any differently than yours.
Link to comment
Share on other sites

Two other ideas for you:

 

If your goal is to constantly call a function after each tick, and you're not looking to only do it for a particular amount of time (I noticed you infinitely repeated your tween), you can just add a listener to the core ticker:

TweenLite.ticker.addEventListener("tick", yourFunction);

Or, if you'd rather use a tween (which is totally fine), a slightly cleaner option is to use a blank object, like {} instead of your dummyPoint. You don't actually have to tween anything:

TweenMax.to({}, 10, {repeat:-1, onUpdate:myFunction});
function myFunction():void {
     //This function will be called repeatedly.
}
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...