GODPAPER | All Packages | All Classes | Index | Frames No Frames |
Tween

Package | starling.animation
Class | public class Tween
Inheritance | Tween EventDispatcher Object
Implements | IAnimatable

A Tween animates numeric properties of objects. It uses different transition functions to give the animations various styles.

The primary use of this class is to do standard animations like movement, fading, rotation, etc. But there are no limits on what to animate; as long as the property you want to animate is numeric (`int, uint, Number`), the tween can handle it. For a list of available Transition types, look at the "Transitions" class.

Here is an example of a tween that moves an object to the right, rotates it, and fades it out:

          var tween:Tween = new Tween(object, 2.0, Transitions.EASE_IN_OUT);
          tween.animate("x", object.x + 50);
          tween.animate("rotation", deg2rad(45));
          tween.fadeTo(0);    // equivalent to 'animate("alpha", 0)'
          Starling.juggler.add(tween);

Note that the object is added to a juggler at the end of this sample. That's because a tween will only be executed if its "advanceTime" method is executed regularly - the juggler will do that for you, and will remove the tween when it is finished.

See also

Juggler
Transitions

Public Properties

| Property | Defined By
--- | --- | ---
|  | currentTime : Number [read-only] The time that has passed since the tween was created (in seconds). | Tween
|  | delay : Number The delay before the tween is started (in seconds). | Tween
|  | isComplete : Boolean [read-only] Indicates if the tween is finished. | Tween
|  | nextTween : Tween Another tween that will be started (i.e. | Tween
|  | onComplete : Function A function that will be called when the tween is complete. | Tween
|  | onCompleteArgs : Array The arguments that will be passed to the 'onComplete' function. | Tween
|  | onRepeat : Function A function that will be called each time the tween finishes one repetition (except the last, which will trigger 'onComplete'). | Tween
|  | onRepeatArgs : Array The arguments that will be passed to the 'onRepeat' function. | Tween
|  | onStart : Function A function that will be called when the tween starts (after a possible delay). | Tween
|  | onStartArgs : Array The arguments that will be passed to the 'onStart' function. | Tween
|  | onUpdate : Function A function that will be called each time the tween is advanced. | Tween
|  | onUpdateArgs : Array The arguments that will be passed to the 'onUpdate' function. | Tween
|  | progress : Number [read-only] The current progress between 0 and 1, as calculated by the transition function. | Tween
|  | repeatCount : int The number of times the tween will be executed. | Tween
|  | repeatDelay : Number The amount of time to wait between repeat cycles (in seconds). | Tween
|  | reverse : Boolean Indicates if the tween should be reversed when it is repeating. | Tween
|  | roundToInt : Boolean Indicates if the numeric values should be cast to Integers. | Tween
|  | target : Object [read-only] The target object that is animated. | Tween
|  | totalTime : Number [read-only] The total time the tween will take per repetition (in seconds). | Tween
|  | transition : String The transition method used for the animation. | Tween
|  | transitionFunc : Function The actual transition function used for the animation. | Tween

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | Tween(target:Object, time:Number, transition:Object = linear) Creates a tween with a target, duration (in seconds) and a transition function. | Tween
|  | addEventListener(type:String, listener:Function):void Registers an event listener at a certain object. | EventDispatcher
|  | advanceTime(time:Number):void Advance the time by a number of seconds. | Tween
|  | animate(property:String, endValue:Number):void Animates the property of the target to a certain value. | Tween
|  | dispatchEvent(event:Event):void Dispatches an event to all objects that have registered listeners for its type. | EventDispatcher
|  | dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void Dispatches an event with the given parameters to all objects that have registered listeners for the given type. | EventDispatcher
|  | fadeTo(alpha:Number):void Animates the 'alpha' property of an object to a certain target value. | Tween
|  | getEndValue(property:String):Number The end value a certain property is animated to. | Tween
|  | hasEventListener(type:String):Boolean Returns if there are listeners registered for a certain event type. | EventDispatcher
|  | moveTo(x:Number, y:Number):void Animates the 'x' and 'y' properties of an object simultaneously. | Tween
|  | removeEventListener(type:String, listener:Function):void Removes an event listener from the object. | EventDispatcher
|  | removeEventListeners(type:String = null):void Removes all event listeners with a certain type, or all of them if type is null. | EventDispatcher
|  | reset(target:Object, time:Number, transition:Object = linear):Tween Resets the tween to its default values. | Tween
|  | scaleTo(factor:Number):void Animates the 'scaleX' and 'scaleY' properties of an object simultaneously. | Tween

Property Detail

currentTime | property

`currentTime:Number` [read-only]

The time that has passed since the tween was created (in seconds).

Implementation
`public function get currentTime():Number`

delay | property |

`delay:Number`

The delay before the tween is started (in seconds).

The default value is `0`.

Implementation
`public function get delay():Number`
`public function set delay(value:Number):void`

isComplete | property |

`isComplete:Boolean` [read-only]

Indicates if the tween is finished.

Implementation
`public function get isComplete():Boolean`

nextTween | property |

`nextTween:Tween`

Another tween that will be started (i.e. added to the same juggler) as soon as this tween is completed.

Implementation
`public function get nextTween():Tween`
`public function set nextTween(value:Tween):void`

onComplete | property |

`onComplete:Function`

A function that will be called when the tween is complete.

Implementation
`public function get onComplete():Function`
`public function set onComplete(value:Function):void`

onCompleteArgs | property |

`onCompleteArgs:Array`

The arguments that will be passed to the 'onComplete' function.

Implementation
`public function get onCompleteArgs():Array`
`public function set onCompleteArgs(value:Array):void`

onRepeat | property |

`onRepeat:Function`

A function that will be called each time the tween finishes one repetition (except the last, which will trigger 'onComplete').

Implementation
`public function get onRepeat():Function`
`public function set onRepeat(value:Function):void`

onRepeatArgs | property |

`onRepeatArgs:Array`

The arguments that will be passed to the 'onRepeat' function.

Implementation
`public function get onRepeatArgs():Array`
`public function set onRepeatArgs(value:Array):void`

onStart | property |

`onStart:Function`

A function that will be called when the tween starts (after a possible delay).

Implementation
`public function get onStart():Function`
`public function set onStart(value:Function):void`

onStartArgs | property |

`onStartArgs:Array`

The arguments that will be passed to the 'onStart' function.

Implementation
`public function get onStartArgs():Array`
`public function set onStartArgs(value:Array):void`

onUpdate | property |

`onUpdate:Function`

A function that will be called each time the tween is advanced.

Implementation
`public function get onUpdate():Function`
`public function set onUpdate(value:Function):void`

onUpdateArgs | property |

`onUpdateArgs:Array`

The arguments that will be passed to the 'onUpdate' function.

Implementation
`public function get onUpdateArgs():Array`
`public function set onUpdateArgs(value:Array):void`

progress | property |

`progress:Number` [read-only]

The current progress between 0 and 1, as calculated by the transition function.

Implementation
`public function get progress():Number`

repeatCount | property |

`repeatCount:int`

The number of times the tween will be executed. Set to '0' to tween indefinitely.

The default value is `1`.

Implementation
`public function get repeatCount():int`
`public function set repeatCount(value:int):void`

repeatDelay | property |

`repeatDelay:Number`

The amount of time to wait between repeat cycles (in seconds).

The default value is `0`.

Implementation
`public function get repeatDelay():Number`
`public function set repeatDelay(value:Number):void`

reverse | property |

`reverse:Boolean`

Indicates if the tween should be reversed when it is repeating. If enabled, every second repetition will be reversed.

The default value is `false`.

Implementation
`public function get reverse():Boolean`
`public function set reverse(value:Boolean):void`

roundToInt | property |

`roundToInt:Boolean`

Indicates if the numeric values should be cast to Integers.

The default value is `false`.

Implementation
`public function get roundToInt():Boolean`
`public function set roundToInt(value:Boolean):void`

target | property |

`target:Object` [read-only]

The target object that is animated.

Implementation
`public function get target():Object`

totalTime | property |

`totalTime:Number` [read-only]

The total time the tween will take per repetition (in seconds).

Implementation
`public function get totalTime():Number`

transition | property |

`transition:String`

The transition method used for the animation.

Implementation
`public function get transition():String`
`public function set transition(value:String):void`

See also

Transitions

transitionFunc | property |

`transitionFunc:Function`

The actual transition function used for the animation.

Implementation
`public function get transitionFunc():Function`
`public function set transitionFunc(value:Function):void`
Constructor Detail

Tween | () | Constructor

`public function Tween(target:Object, time:Number, transition:Object = linear)`

Creates a tween with a target, duration (in seconds) and a transition function.

Parameters

| `target:Object` — the object that you want to animate
| `time:Number` — the duration of the Tween (in seconds)
| `transition:Object` (default = `linear`)`` — can be either a String (e.g. one of the constants defined in the Transitions class) or a function. Look up the 'Transitions' class for a documentation about the required function signature.

Method Detail

advanceTime | () | method

`public function advanceTime(time:Number):void`

Advance the time by a number of seconds.

Parameters

| `time:Number` — in seconds.

animate | () | method |

`public function animate(property:String, endValue:Number):void`

Animates the property of the target to a certain value. You can call this method multiple times on one tween.

Parameters

| `property:String`
| `endValue:Number`

fadeTo | () | method |

`public function fadeTo(alpha:Number):void`

Animates the 'alpha' property of an object to a certain target value.

Parameters

| `alpha:Number`

getEndValue | () | method |

`public function getEndValue(property:String):Number`

The end value a certain property is animated to. Throws an ArgumentError if the property is not being animated.

Parameters

| `property:String`

Returns

| `Number`

moveTo | () | method |

`public function moveTo(x:Number, y:Number):void`

Animates the 'x' and 'y' properties of an object simultaneously.

Parameters

| `x:Number`
| `y:Number`

reset | () | method |

`public function reset(target:Object, time:Number, transition:Object = linear):Tween`

Resets the tween to its default values. Useful for pooling tweens.

Parameters

| `target:Object`
| `time:Number`
| `transition:Object` (default = `linear`)``

Returns

| `Tween`

scaleTo | () | method |

`public function scaleTo(factor:Number):void`

Animates the 'scaleX' and 'scaleY' properties of an object simultaneously.

Parameters

| `factor:Number`

Thu Jan 16 2014, 01:11 PM +08:00