Another Reason to Love TweenLite

I just found a useful function in the TweenLite library, which is great for easily sequencing multiple function calls. To call myFunction() in half a second with param1 and param2, do this:

[as]TweenLite.delayedCall(0.5, myFunction, [param1,param2]);[/as]
which is a lot less code than:
[as]var tmr:Timer = new Timer(500, 1);
tmr.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerEvent);
tmr.start();
private function onTimerEvent(event:Event):void{
myFunction(param1,param2);
}[/as]

TweenLite seems to have quickly become something of a Flash standard. It’s a great library that is well maintained and just works.

8 Responses

  1. vamapaull says:

    I didn’t know it can do that
    Now I know I’ll use TweemLite even more 🙂

  2. mckinley says:

    Excellent idea!

  3. Jack says:

    One other benefit of using delayedCall() is that you can call TweenLite.killDelayedCallsTo(myFunction) to…um…kill all delayed calls to a particular function, saving more code and headache in certain scenarios.

    There’s additional flexibility for setting up a sequence of calls (or tweens of course) in v11’s new TimelineLite and TimelineMax classes. They’re like ActionScript-based MovieClip timelines where you can position various tweens and/or callbacks on the timeline and then control the whole group easily with play(), stop(), gotoAndPlay(), gotoAndStop(), reverse(), add labels, and even change the timeScale! Heck, you could tween the timeScale or time properties for advanced effects too (fastforward/rewind with easing). So if you’re looking to sequence things (including function calls), you may want to check it out.

    Oh, and in v11 of TweenLite, you can tell a delayedCall() to use frames instead of time/seconds as its duration if you prefer. http://blog.greensock.com/v11beta/

    Thanks Felix!

  4. agustina says:

    te amO lichiii..

  5. Erin says:

    You can try flash.utils.setTimeout(myFunction , 500 , param1,param2);
    It comes from flash package…same as delayedCall()

    BTW, I love TweenLite/Max!!!

  6. Jack says:

    There are two down sides to using flash.utils.setTimeout(myFunction , 500 , param1,param2);

    1) There are known bugs in setTimeout(), particularly on the Mac if I remember correctly

    2) If you use TweenLite.delayedCall(), it’ll always be synced with all the tween updates (which may or may not be important to you)

  7. paul says:

    hi there

    I am also trying to use tweenLite to create a time delay when loadinig an swf, this is what I have but not sure if it is correct, can anyone help direct me??

    private function onMenuItemClick( event:MouseEvent ):void
    {

    circleMenu.scrollToItem( event.currentTarget as DisplayObject );
    event.target.load(new URLRequest(images[event.target.name].@swf));
    lastMoviePlaying = event.target;
    lastMoveIndex = event.target.name;
    TweenLite.delayedCall(0.5, loadMovie); // <<<<<TweenLite attached

    }

    private function loadMovie():void <<<not sure if this is correct???
    { trace();
    }

  8. […] ???Another Reason to Love TweenLite […]

Leave a Reply

Your email address will not be published. Required fields are marked *