API Documentation for: 0.6.0
Show:

Timeline Class

Extends EventDispatcher
Defined in: Timeline:42
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:42

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:400

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:228

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:179

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:391

dispatchEvent

(
  • eventObj
)
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.

Returns:

Boolean:

Returns the value of eventObj.defaultPrevented.

getCurrentLabel

() String

Defined in getCurrentLabel:271

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:253

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:292

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:302

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.

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

() deprecated protected

REMOVED. Removed in favor of using MySuperClass_constructor. See extend and promote for details.

There is an inheritance tutorial distributed with EaselJS in /tutorials/Inheritance.

off

(
  • type
  • listener
  • [useCapture]
)

Inherited from EventDispatcher: off:254

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:182

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.removeAllEventListeners();

 // 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:202

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:370

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:243

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:336

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:312

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:360

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:382

Returns a string representation of this object.

Returns:

String:

a string representation of the instance.

updateDuration

()

Defined in updateDuration:346

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.

willTrigger

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type on this object or any of its ancestors (parent, parent's parent, etc). A return value of true indicates that if a bubbling event of the specified type is dispatched from this object, it will trigger at least one listener.

This is similar to hasEventListener, but it searches the entire event flow for a listener, not just this object.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

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

Properties

_captureListeners

Object protected

_labelList

ArrayObject protected

Defined in _labelList:118

_labels

Object protected

Defined in _labels:111

_listeners

Object protected

Inherited from EventDispatcher: _listeners:94

_paused

Boolean protected

Defined in _paused:97

_prevPos

Number protected

Defined in _prevPos:133

Default: -1

_prevPosition

Number protected

Defined in _prevPosition:125

Default: 0

_tweens

ArrayTween protected

Defined in _tweens:104

_useTicks

Boolean protected

Defined in _useTicks:141

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.

position

Object

Defined in position:88

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:171

Available since 0.5.0

Called whenever the timeline's position changes.