Packagestarling.animation
Classpublic class Tween
InheritanceTween Inheritance EventDispatcher Inheritance 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
 PropertyDefined 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
 MethodDefined By
  
Tween(target:Object, time:Number, transition:Object = linear)
Creates a tween with a target, duration (in seconds) and a transition function.
Tween
 Inherited
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
  
animatesProperty(property:String):Boolean
Indicates if a property with the given name is being animated by this tween.
Tween
 Inherited
dispatchEvent(event:Event):void
Dispatches an event to all objects that have registered listeners for its type.
EventDispatcher
 Inherited
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
 Inherited
hasEventListener(type:String, listener:Function = null):Boolean
If called with one argument, figures out if there are any listeners registered for the given event type.
EventDispatcher
  
moveTo(x:Number, y:Number):void
Animates the 'x' and 'y' properties of an object simultaneously.
Tween
 Inherited
removeEventListener(type:String, listener:Function):void
Removes an event listener from the object.
EventDispatcher
 Inherited
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
  
rotateTo(angle:Number, type:String = rad):void
Animates the 'rotation' property of an object to a certain target value, using the smallest possible arc.
Tween
  
scaleTo(factor:Number):void
Animates the 'scaleX' and 'scaleY' properties of an object simultaneously.
Tween
Property Detail
currentTimeproperty
currentTime:Number  [read-only]

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


Implementation
    public function get currentTime():Number
delayproperty 
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
isCompleteproperty 
isComplete:Boolean  [read-only]

Indicates if the tween is finished.


Implementation
    public function get isComplete():Boolean
nextTweenproperty 
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
onCompleteproperty 
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
onCompleteArgsproperty 
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
onRepeatproperty 
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
onRepeatArgsproperty 
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
onStartproperty 
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
onStartArgsproperty 
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
onUpdateproperty 
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
onUpdateArgsproperty 
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
progressproperty 
progress:Number  [read-only]

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


Implementation
    public function get progress():Number
repeatCountproperty 
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
repeatDelayproperty 
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
reverseproperty 
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
roundToIntproperty 
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
targetproperty 
target:Object  [read-only]

The target object that is animated.


Implementation
    public function get target():Object
totalTimeproperty 
totalTime:Number  [read-only]

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


Implementation
    public function get totalTime():Number
transitionproperty 
transition:String

The transition method used for the animation.


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

See also

transitionFuncproperty 
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.

Some property types are handled in a special way:

Parameters

property:String
 
endValue:Number

animatesProperty()method 
public function animatesProperty(property:String):Boolean

Indicates if a property with the given name is being animated by this tween.

Parameters

property:String

Returns
Boolean
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
rotateTo()method 
public function rotateTo(angle:Number, type:String = rad):void

Animates the 'rotation' property of an object to a certain target value, using the smallest possible arc. 'type' may be either 'rad' or 'deg', depending on the unit of measurement.

Parameters

angle:Number
 
type:String (default = rad)

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

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

Parameters

factor:Number