Jump to content
GreenSock

TimelineMax

.addCallback()

.addCallback( callback:Function, position:*, params:Array, scope:* ) : TimelineMax

Inserts a callback at a particular position.

Parameters

callback: Function

The function to be called

position: *

The time in seconds (or frames for frames-based timelines) or label at which the callback should be inserted. For example, myTimeline.addCallback(myFunction, 3) would call myFunction() 3 seconds into the timeline, and myTimeline.addCallback(myFunction, "myLabel") would call it at the “myLabel” label.myTimeline.addCallback(myFunction, "+=2") would insert the callback 2 seconds after the end of the timeline.

params: Array

(default = null) — An Array of parameters to pass the callback

scope: *

(default = null) — The scope in which the callback should be called (basically, what “this” refers to in the function). NOTE: this parameter only pertains to the JavaScript and AS2 versions; it is omitted in AS3.

Returns : TimelineMax

self (makes chaining easier)

 

Details

Inserts a callback at a particular position. The callback is technically considered a zero-duration tween, so if you getChildren() there will be a tween returned for each callback. You can discern a callback from other tweens by the fact that its target is a function matching its vars.onComplete and its duration is zero.

If your goal is to append the callback to the end of the timeline, it would be easier (more concise) to use the call() method. Technically the add() method can accommodate adding a callback too (like myTimeline.add(myFunction, 2) or myTimeline.add(myFunction, "+=2")) but add() doesn't accommodate parameters.

Copyright 2017, GreenSock. All rights reserved. This work is subject to theterms of useor for Club GreenSock members, the software agreement that was issued with the membership.
×