API Documentation for: 0.5.0
Show:

Timeline Class

Extends EventDispatcher
Defined in: Timeline:39
Module: TweenJS

The Timeline class synchronizes multiple tweens and allows them to be controlled as a group. Please note that if a timeline is looping, the tweens on it may appear to loop even if the "loop" property of the tween is false.

Constructor

Timeline

(
  • tweens
  • labels
  • props
)

Defined in Timeline:39

Parameters:

  • tweens Array

    An array of Tweens to add to this timeline. See addTween for more info.

  • labels Object

    An object defining labels for using gotoAndPlay/gotoAndStop. See setLabels for details.

  • props Object

    The configuration properties to apply to this tween instance (ex. {loop:true}). All properties default to false. Supported props are:

    • loop: sets the loop property on this tween.
    • useTicks: uses ticks for all durations instead of milliseconds.
    • ignoreGlobalPause: sets the ignoreGlobalPause property on this tween.
    • paused: indicates whether to start the tween paused.
    • position: indicates the initial position for this timeline.
    • onChange: specifies a listener to add for the change event.

Methods

_dispatchEvent

(
  • eventObj
  • eventPhase
)
protected

Parameters:

_goto

() protected

Defined in _goto:409

addEventListener

(
  • type
  • listener
  • [useCapture]
)
Function | Object

Adds the specified event listener. Note that adding multiple listeners to the same function will result in multiple callbacks getting fired.

Example

 displayObject.addEventListener("click", handleClick);
 function handleClick(event) {
    // Click happened.
 }

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function | Object:

Returns the listener for chaining or assignment.

addLabel

(
  • label
  • position
)

Defined in addLabel:237

Adds a label that can be used with gotoAndPlay/gotoAndStop.

Parameters:

  • label String

    The label name.

  • position Number

    The position this label represents.

addTween

(
  • tween
)

Defined in addTween:188

Adds one or more tweens (or timelines) to this timeline. The tweens will be paused (to remove them from the normal ticking system) and managed by this timeline. Adding a tween to multiple timelines will result in unexpected behaviour.

Parameters:

  • tween Object

    The tween(s) to add. Accepts multiple arguments.

Returns:

Tween The first tween that was passed in.

clone

() protected

Defined in clone:400

dispatchEvent

(
  • eventObj
  • [target]
)
Boolean

Dispatches the specified event to all listeners.

Example

 // Use a string event
 this.dispatchEvent("complete");

 // Use an Event instance
 var event = new createjs.Event("progress");
 this.dispatchEvent(event);

Parameters:

  • eventObj Object | String | Event

    An object with a "type" property, or a string type. While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used, dispatchEvent will construct an Event instance with the specified type.

  • [target] Object optional

    The object to use as the target property of the event object. This will default to the dispatching object. This parameter is deprecated and will be removed.

Returns:

Boolean:

Returns the value of eventObj.defaultPrevented.

getCurrentLabel

() String

Defined in getCurrentLabel:280

Returns the name of the label on or immediately before the current position. For example, given a timeline with two labels, "first" on frame index 4, and "second" on frame 8, getCurrentLabel would return:

  • null if the current position is 2.
  • "first" if the current position is 4.
  • "first" if the current position is 7.
  • "second" if the current position is 15.

Returns:

String:

The name of the current label or null if there is no label

getLabels

() ArrayObject

Defined in getLabels:262

Returns a sorted list of the labels defined on this timeline.

Returns:

ArrayObject:

A sorted array of objects with label and position properties.

gotoAndPlay

(
  • positionOrLabel
)

Defined in gotoAndPlay:301

Unpauses this timeline and jumps to the specified position or label.

Parameters:

  • positionOrLabel String | Number

    The position in milliseconds (or ticks if useTicks is true) or label to jump to.

gotoAndStop

(
  • positionOrLabel
)

Defined in gotoAndStop:311

Pauses this timeline and jumps to the specified position or label.

Parameters:

  • positionOrLabel String | Number

    The position in milliseconds (or ticks if useTicks is true) or label to jump to.

hasEventListener

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type and useCapture value.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

Returns true if there is at least one listener for the specified event.

initialize

() protected

Inherited from EventDispatcher but overwritten in initialize:167

Initialization method.

off

(
  • type
  • listener
  • [useCapture]
)

Inherited from EventDispatcher: off:252

A shortcut to the removeEventListener method, with the same parameters and return value. This is a companion to the .on method.

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

on

(
  • type
  • listener
  • [scope]
  • [once=false]
  • [data]
  • [useCapture=false]
)
Function

Inherited from EventDispatcher: on:180

A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener only run once, associate arbitrary data with the listener, and remove the listener.

This method works by creating an anonymous wrapper function and subscribing it with addEventListener. The created anonymous function is returned for use with .removeEventListener (or .off).

Example

    var listener = myBtn.on("click", handleClick, null, false, {count:3});
    function handleClick(evt, data) {
        data.count -= 1;
        console.log(this == myBtn); // true - scope defaults to the dispatcher
        if (data.count == 0) {
            alert("clicked 3 times!");
            myBtn.off("click", listener);
            // alternately: evt.remove();
        }
    }

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [scope] Object optional

    The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent).

  • [once=false] Boolean optional

    If true, the listener will remove itself after the first time it is triggered.

  • [data] optional

    Arbitrary data that will be included as the second parameter when the listener is called.

  • [useCapture=false] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function:

Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.

removeAllEventListeners

(
  • [type]
)

Removes all listeners for the specified type, or all listeners of all types.

Example

 // Remove all listeners
 displayObject.removeAllEvenListeners();

 // Remove all click listeners
 displayObject.removeAllEventListeners("click");

Parameters:

  • [type] String optional

    The string type of the event. If omitted, all listeners for all types will be removed.

removeEventListener

(
  • type
  • listener
  • [useCapture]
)

Removes the specified event listener.

Important Note: that you must pass the exact function reference used when the event was added. If a proxy function, or function closure is used as the callback, the proxy/closure reference must be used - a new proxy or closure will not work.

Example

 displayObject.removeEventListener("click", handleClick);

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

removeTween

(
  • tween
)

Defined in removeTween:211

Removes one or more tweens from this timeline.

Parameters:

  • tween Object

    The tween(s) to remove. Accepts multiple arguments.

Returns:

Boolean Returns true if all of the tweens were successfully removed.

resolve

(
  • positionOrLabel
)

Defined in resolve:379

If a numeric position is passed, it is returned unchanged. If a string is passed, the position of the corresponding frame label will be returned, or null if a matching label is not defined.

Parameters:

  • positionOrLabel String | Number

    A numeric position value or label string.

setLabels

(
  • o
)

Defined in setLabels:252

Defines labels for use with gotoAndPlay/Stop. Overwrites any previously set labels.

Parameters:

  • o Object

    An object defining labels for using gotoAndPlay/Stop in the form {labelName:time} where time is in milliseconds (or ticks if useTicks is true).

setPaused

(
  • value
)

Defined in setPaused:345

Pauses or plays this timeline.

Parameters:

  • value Boolean

    Indicates whether the tween should be paused (true) or played (false).

setPosition

(
  • value
  • [actionsMode]
)
Boolean

Defined in setPosition:321

Advances the timeline to the specified position.

Parameters:

  • value Number

    The position to seek to in milliseconds (or ticks if useTicks is true).

  • [actionsMode] Number optional

    parameter specifying how actions are handled. See the Tween setPosition method for more details.

Returns:

Boolean:

Returns true if the timeline is complete (ie. the full timeline has run & loop is false).

tick

(
  • delta
)

Defined in tick:369

Advances this timeline by the specified amount of time in milliseconds (or ticks if useTicks is true). This is normally called automatically by the Tween engine (via Tween.tick), but is exposed for advanced uses.

Parameters:

  • delta Number

    The time to advance in milliseconds (or ticks if useTicks is true).

toString

() String

Inherited from EventDispatcher but overwritten in toString:391

Returns a string representation of this object.

Returns:

String:

a string representation of the instance.

updateDuration

()

Defined in updateDuration:355

Recalculates the duration of the timeline. The duration is automatically updated when tweens are added or removed, but this method is useful if you modify a tween after it was added to the timeline.

Properties

_captureListeners

Object protected

_labelList

ArrayObject protected

Defined in _labelList:135

_labels

Object protected

Defined in _labels:128

_listeners

Object protected

_paused

Boolean protected

Defined in _paused:114

_prevPos

Number protected

Defined in _prevPos:150

Default: -1

_prevPosition

Number protected

Defined in _prevPosition:142

Default: 0

_tweens

ArrayTween protected

Defined in _tweens:121

_useTicks

Boolean protected

Defined in _useTicks:158

Default: false

duration

Number

Defined in duration:73

Read-only property specifying the total duration of this timeline in milliseconds (or ticks if useTicks is true). This value is usually automatically updated as you modify the timeline. See updateDuration for more information.

ignoreGlobalPause

Boolean

Causes this timeline to continue playing when a global pause is active.

loop

Boolean

Defined in loop:81

If true, the timeline will loop when it reaches the end. Can be set via the props param.

onChange

Function deprecated

Defined in onChange:89

Deprecated: Use addEventListener and the "change" event.

REMOVED. Use addEventListener and the change event.

position

Object

Defined in position:97

Read-only. The current normalized position of the timeline. This will always be a value between 0 and duration. Changing this property directly will have no effect.

Events

change

Defined in change:106

Available since 0.5.0

Called whenever the timeline's position changes.