Tween
Kind of class: | class |
---|---|
Inherits from: | EventDispatcher < CoreObject |
Implements: | |
Known subclasses: | |
Version: | 07/11/07 |
Author: | Aaron Clinger, Mike Creighton |
Classpath: | org.casalib.transitions.Tween |
File last modified: | Monday, 01 December 2008, 13:34:40 |
Simple and easily extendable tween class.
Advantages of using this tween class over others:
Advantages of using this tween class over others:
- Does not include any tweening equations, only the equation(s) a user defines. This allows for a much smaller class/swf file.
- Using built in events/event dispatcher you are able to tween more than one value.
- Ability to tween any value, not only MovieClip properties.
- Works with all easing equations that follow the currentTime, startPosition, endPosition, totalTime standard.
Example:
-
function onEasePosition(sender:Tween, position:Number):Void { this.box_mc._x = this.box_mc._y = position; } var slideMotion:Tween = new Tween(com.robertpenner.easing.Bounce.easeOut, 0, 250, 1.5); slideMotion.addEventObserver(this, Tween.EVENT_POSITION, "onEasePosition"); slideMotion.start();
If you want to tween an item on a curve you can use the org.casalib.math.geom.Ellipse class and its getPointOfDegree function:
function onCurvePosition(sender:Tween, degree:Number):Void { var position:Point = this.curve.getPointOfDegree(degree); this.box_mc._x = position.getX(); this.box_mc._y = position.getY(); } var curve:Ellipse = new Ellipse(20, 50, 300, 200); var slideMotion:Tween = new Tween(com.robertpenner.easing.Elastic.easeInOut, 0, 360, 4); slideMotion.addEventObserver(this, Tween.EVENT_POSITION, "onCurvePosition"); slideMotion.start();
Usage note:
- If you want to tween a property use PropertyTween.
Events broadcasted to listeners:
onStart = function (sender:Tween) {}
onStop = function (sender:Tween) {}
onResume = function (sender:Tween) {}
onProgress = function (sender:Tween, progress:Percent) {}
onPosition = function (sender:Tween, position:Number) {}
onComplete = function (sender:Tween) {}
Summary
Constructor
- Tween (equation:Function, startPos:Number, endPos:Number, duration:Number, useFrames:Boolean)
- Creates and defines tween.
Class properties
- EVENT_START : String
- EVENT_STOP : String
- EVENT_RESUME : String
- EVENT_POSITION : String
- EVENT_PROGRESS : String
- EVENT_COMPLETE : String
Instance methods
- start : Void
- Starts tween from start position.
- stop : Void
- Stops tween at current position.
- resume : Void
- Resumes tween from stopped position.
- continueTo (endPos:Number, duration:Number) : Void
- Instructs to tween from its current position to a new finish and duration position.
- destroy : Void
- Removes any internal variables, intervals, enter frames, internal MovieClips and event observers to allow the object to be garbage collected.Instance methods inherited from EventDispatcherInstance methods inherited from CoreObject
Constructor
Tween
function Tween (
equation:Function,
startPos:Number,
endPos:Number,
duration:Number,
useFrames:Boolean)
Creates and defines tween.
Parameters:
equation :
Tween equation.
startPos :
The starting value of the tween.
endPos :
The ending value of the tween.
duration :
Length of time of the tween.
useFrames:
[optional] Indicates to use frames
true
, or seconds false
in relation to the value specified in the duration
parameter; defaults to false
.Usage note:
- The function specified in the
equation
parameter must follow the (currentTime, startPosition, endPosition, totalTime) parameter standard.
See also:
Class properties
EVENT_COMPLETE
static EVENT_COMPLETE:String = 'onComplete'
(read,write)
EVENT_POSITION
static EVENT_POSITION:String = 'onPosition'
(read,write)
EVENT_PROGRESS
static EVENT_PROGRESS:String = 'onProgress'
(read,write)
EVENT_RESUME
static EVENT_RESUME:String = 'onResume'
(read,write)
EVENT_START
static EVENT_START:String = 'onStart'
(read,write)
EVENT_STOP
static EVENT_STOP:String = 'onStop'
(read,write)
Instance methods
continueTo
function continueTo (
endPos:Number,
duration:Number) : Void
Instructs to tween from its current position to a new finish and duration position.
Parameters:
endPos :
The ending value of the tween.
duration:
Length of time of the tween.
Usage note:
- Will automatically start tween if currently stopped.
destroy
function destroy (
) : Void
Removes any internal variables, intervals, enter frames, internal MovieClips and event observers to allow the object to be garbage collected.
Always call
# Always call
function onEasePosition(sender:Tween, position:Number):Void { this.box_mc._x = this.box_mc._y = position; } var slideMotion:Tween = new Tween(com.robertpenner.easing.Bounce.easeOut, 0, 250, 1.5); slideMotion.addEventObserver(this, Tween.EVENT_POSITION, "onEasePosition"); slideMotion.start();before deleting last object pointer.
Overrides:
Specified by:
resume
function resume (
) : Void
Resumes tween from stopped position.
Events broadcasted to listeners:
onResume = function (sender:Tween) {}
Specified by:
start
function start (
) : Void
Starts tween from start position.
Events broadcasted to listeners:
onStart = function (sender:Tween) {}
Specified by:
stop
function stop (
) : Void
Stops tween at current position.
Events broadcasted to listeners:
onStop = function (sender:Tween) {}
Specified by: