Animator Documentation
Author: Alex Uhlmann
Last Modified: 09/24/05 19:03:20
Summary
Animator class:
Animator Properties:
Animator Methods:
version: Documentation not provided.
description:
Animator combines user defined property(ies) or method(s), tween-engines and AnimationPackage. It allows to create custom animations easily. Animator is used by most classes in AnimationPackage that use animations. The tween engine used is either Macromedia's mx.effects.Tween or de.alex_uhlmann.animationpackage.utility.FrameTween based on Andre Michelle's FrameBasedInterval and ImpulsDispatcher. Animator can handle single and multiple properties and single and multiple methods.
Example 1: To emulate the ColorBrightness class.
Take a look at some other classes of AnimationPackage, most of them use Animator internally. ColorTransform and ColorDodge i.e.var myAnimator:Animator = new Animator(); myAnimator.animationStyle(5000, Elastic.easeOut, "onCallback"); var myColorFX:ColorFX = new ColorFX(mc); myAnimator.caller = this; myAnimator.start = [myColorFX.getBrightness()]; myAnimator.end = [50]; myAnimator.setter = [[myColorFX,"setBrightness"]]; myAnimator.run();
Animator also might come in handy to animate different properties of shapes offered by the drawing package. Take a look at the Rectangle class documentation for an example.
Example 1: (Example .swf) If the start and end arrays are longer than the setter array than Animator figures that you want all the properties send to one function. Do crazy shape manipulations.
var myStar:Star = new Star(330,200,50,60,6)
myStar.lineStyle();
myStar.fillStyle(0x9C3031);
myStar.draw();
var myAnimator:Animator = new Animator();
myAnimator.animationStyle(5000,Circ.easeInOut);
myAnimator.start = [50,60];
myAnimator.end = [0,200];
//Try this one for yourself. A negative innerRadius parameter results in more complex star.
//This Bug of the Star class is actually a feature and will not be fixed. ( ;
//myAnimator.end = [-125,200];
myAnimator.setter = [[this,"morph"]];
myAnimator.run();
function morph(innerRadius:Number,outerRadius:Number) {
myStar.setInnerRadius(innerRadius);
myStar.setOuterRadius(outerRadius);
myStar.draw();
}
Example 1: (Example .swf) This examples illustrates how you can animate more complex drawing created with the Drawer class. If you create a more imaginary drawing, which might even make some sense, please let me know. I would be happy to replace it with my ugly one here. ( ;
var myCubicCurve:CubicCurve = new CubicCurve(0,0,60,100,260,80,320,0);
myCubicCurve.lineStyle();
var myLine:Line = new Line(0,0,320,0);
myLine.lineStyle();
var myDraw_mc:MovieClip = this.createEmptyMovieClip("draw_mc",999);
var myDrawer:Drawer = new Drawer(myDraw_mc);
myDrawer.addChild(myLine);
myDrawer.addChild(myCubicCurve);
myDrawer.drawBy();
myDrawer.fillStyle(0xff0000);
myDrawer.fill();
var myAnimator:Animator = new Animator();
myAnimator.animationStyle(4000,Elastic.easeInOut);
myAnimator.start = [100,200,0];
myAnimator.end = [540,500,150];
myAnimator.setter = [[this,"morph"]];
myAnimator.run();
function morph(y2:Number,x3:Number,y3:Number) {
myDrawer.removeChild(myLine);
myDrawer.removeChild(myCubicCurve);
myCubicCurve.setY2(y2);
myCubicCurve.setX3(x3);
myCubicCurve.setY3(y3);
myDrawer.addChild(myLine);
myDrawer.addChild(myCubicCurve);
myDrawer.drawBy();
myDrawer.fill();
}
Under the hood, to assign values to method(s) and/or property(ies), Animator uses the optimized TweenAction class.
usage:
var myAnimator:Animator = new Animator();(Object) Object that calls the Animator.
(Array) Array of value or values to start animation with.
(Array) Targeted amount or amounts to animate to.
(Array) 2 dimensional array. First dimension holds an object as the first element and the corresponding function or property as the second element as a String. See run().
(Array) Same API as start. When multiple animation targets (i.e. movieclips) are animated, multiStart makes sure different start values are considered. It replaces start. See other IAnimatable classes for examples on implementation. i.e. the Move class.
(Array) Same API as setter. When multiple animation targets (i.e. movieclips) are animated, multiSetter replaces setter. See other IAnimatable classes for examples on implementation. i.e. the Move class.
(Number) Duration of animation in milliseconds or frames. Default is milliseconds.
(Object) Easing equation in Robert Penner style. Default equation is Linear.easeNone. www.robertpenner.com/easing/
(String) Function to invoke after animation. See APCore class.
description: send a custom method or methods to animate in a specified time and easing equation.
usage:
myAnimator.run();
myAnimator.run(duration);
myAnimator.run(duration, callback);
myAnimator.run(duration, easing, callback);
parameters:
returns: void
description: similar to the run() method. Offers start and end parameters.
usage:
myInstance.animate(start, end);
parameters:
returns: void
description: jumps to a specific step of the animation and stays there.
usage:
myInstance.goto(percentage);
parameters:
returns: void
description: set the animation style properties for your animation. Notice that if your easing equation supports additional parameters you can send those parameters with the easing parameter in animationStyle. You have to send an Array as easing parameter. The first element has to be the easing equation in Robert Penner style. The following parameters can be your additional parameters. i.e.:
See also "Customizable easing equations" in readme for more information.var myRotation:Rotation = new Rotation(mc); myRotation.animationStyle(2000,[Back.easeOut,4]); myRotation.run(360);
usage:
myAnimator.animationStyle(duration);
myAnimator.animationStyle(duration, callback);
myAnimator.animationStyle(duration, easing, callback);
parameters:
returns: Void.
description: rounds animation results to integers. (might be usefull for animating pixelfonts). Default is false.
usage:
myInstance.roundResult(event, listener);
parameters:
true rounds the result. Animates with integers. Less accuracy.returns: Void.
description: Flash does not guaranteed that time-based tweening will reach the end value(s) of your animation. By default AnimationPackage guarantees that the end value(s) will be reached. The forceEnd method allows you to disable this guarantee and only accept the values from your easing equation. In certain situations this can lead to a smoother ending of the animation. Notice that in frame-based tweening the end value(s) will always be reached.
usage:
myInstance.forceEnd(forceEndVal);
parameters:
true or false.returns: Void.
description: returns the optimization mode. See setOptimizationMode for more information.
usage: getOptimizationMode();
returns: Boolean
description:
Allows to explicitly remove parts of the animation that don't change during
the animation.
This can add additional performance to your animation. Note that
setting this method to true has side effects. If all start and end values match,
the animation won't start and will immediatly invoke an onEnd event.
The order of values returned by getStartValue(s), getCurrentValue(s),
getEndValue(s) and the value property of the eventObject returned
by EventDispatcher might change if you set this method to true. You can
still retrieve the parts of the animation that are actually animated
if you access the Animator instance of your animation class via
myAnimator. Ask myInstance.myAnimator.setter to retrieve
all currently animated parts of the animation. See Animator
documentation. Of cource, if you know your input values you would
probably look at them.
Note that the AnimationCore class offers a static setOptimizationModes method (note the last "s" at the end) that allows you to remove parts of 'all' your animations that don't change during the animation.
usage:
myInstance.setOptimizationMode(optimize);
parameters:
returns: Void.
description: returns the current tween mode used by the instance. Please check with AnimationCore.setTweenModes for more information.
usage: getTweenMode();
returns: String that specifies the tween mode. Either AnimationCore.INTERVAL or AnimationCore.FRAMES.
description: sets the current tween mode used by the instance. Please check with AnimationCore.setTweenModes for more information.
usage: setTweenMode();
parameters:
returns: true if setting tween mode was successful,
false if not successful.
description: returns the current duration mode used by the instance. Please check with AnimationCore.setTweenModes for more information.
usage: getDurationMode();
returns: String that specifies the duration mode. Either AnimationCore.MS or AnimationCore.FRAMES.
description: sets the current duration mode used by the instance. Please check with AnimationCore.setTweenModes for more information.
usage: setDurationMode();
parameters:
returns: true if setting duration mode was successful,
false if not successful.
description: stops the animation if not locked..
usage: myInstance.stop();
returns: true if instance was successfully stopped.
false if instance could not be stopped, because it was locked.
description: pauses the animation if not locked. Call resume() to continue animation.
usage: myInstance.pause();
parameters:
returns: true if instance was successfully paused.
false if instance could not be paused, because it was locked.
description: continues the animation if not locked.
usage: myInstance.resume();
returns: true if instance was successfully resumed.
false if instance could not be resumed, because it was locked.
description: locks the animation to prevent pausing, resuming and stopping. Default is unlocked.
usage: myInstance.lock();
returns: Void.
description: unlocks the animation to allow pausing, resuming and stopping. Default is unlocked.
usage: myInstance.unlock();
returns: Void.
description: checks if the instance is currently animated.
usage: myInstance.isTweening();
returns: true if instance is tweening,
false if instance is not tweening.
description: returns the original, starting value of the current tween.
usage: myInstance.getStartValue();
returns: Number
description: returns the original, starting values of the current tween.
usage: myInstance.getStartValues();
returns: (Array)
description: returns the targeted value of the current tween.
usage: myInstance.getEndValue();
returns: Number
description: returns the targeted values of the current tween.
usage: myInstance.getEndValues();
returns: (Array)
description: returns the current value of the current tween.
usage: myInstance.getCurrentValue();
returns: Number
description: returns the current values of the current tween.
usage: myInstance.getCurrentValues();
returns: (Array)
description: returns the current state of the animation in percentage. Especially usefull in combination with goto().
usage: myInstance.getCurrentPercentage();
returns: Number
description: returns the elapsed time or frames since the current tween started tweening.
usage: myInstance.getDurationElapsed();
returns: Number
description: returns the remaining time or frames since the current tween started tweening.
usage: myInstance.getDurationRemaining();
returns: Number
description: Subscribe to a predefined event. The following standard EventDispatcher events are broadcasted
onStart, broadcasted when animation starts.
onUpdate, broadcasted when animation updates.
onEnd, broadcasted when animation ends.
The even object returned, contains the following properties:
type (String) event broadcasted.
target (Object) event source.
usage:
myAnimator.addEventListener(event, listener);
myAnimator.addEventListener(event, listener, handler);
parameters:
returns: Void.
description: Removes a listener from a subscribed event.
usage:
myAnimator.removeEventListener(event, listener);
myAnimator.removeEventListener(event, listener, handler);
parameters:
returns: Void.
description: GDispatcher specific feature. Removes all listeners for a specific event, or for all events.
usage:
myAnimator.removeAllEventListeners();
myAnimator.removeAllEventListeners(event);
parameters:
returns: Void.
description: GDispatcher specific feature. Checks if a listener is already subscribed to a certain event.
usage:
myAnimator.eventListenerExists(event, listener);
myAnimator.eventListenerExists(event, listener, handler);
parameters:
returns: true if event exists on listener.
false if event doesn't exist on listener.
description: returns a unique ID of the instance. Usefull for associative arrays.
usage: myInstance.getID();
returns: Number
description: returns the name of the class.
usage: myInstance.toString();
returns: String