Scale Documentation
Author: Alex Uhlmann, Ben Jackson
Last Modified: 09/24/05 19:04:07
Summary
Scale class:
Scale Properties:
Scale Methods:
version: Documentation not provided.
description:
Manipulates either the _xscale and _yscale or _width and _height properties of a movieclip or a number of movieclips.
You can specify the duration, easing equation and callback properties either with setting the properies directly or with the animationStyle() method like it is used in de.alex_uhlmann.animationpackage.drawing.
Example 1:
Example 2: The alternative way is shorter. The same like above in one line.var myScale:Scale = new Scale(mc); myScale.animationStyle(2000,Sine.easeOut,"onCallback"); myScale.run(1500,1500);
Example 3: You can also specify the properties via the constructor. This might come in handy if you're using the Sequence or Parallel class. Take a look at their class documentations for more information. The animate() method and its start and end percentage parameters might also be useful.new Scale(mc).run(1500,1500,2000,Sine.easeOut,"onCallback");
Example 4: By default, the start value of your animation is the current value. You can explicitly define the start values either via the setStartValues or run method or via the constructor. Here is one example for the constructor solution. This also might come in handy using composite classes, like Sequence.var myScale:Scale = new Scale(mc,500,500,2000,Circ.easeOut,"onCallback"); myScale.animate(0,100);
var myScale:Scale = new Scale(mc,[10,300],3000,Quad.easeOut); myScales.run();
Example 5: Scretch a movieclip to _xscale 400 in 2 second using elastic easing.
new Scale(mc).run(400,100,2000,Elastic.easeOut);
Example 6: (Example.swf) Scale a movieclip 1500% proportionally in two seconds using circular easing. After animation scale it back to 100%.
new Scale(mc).run(1500,1500,2000,Sine.easeOut,"onCallback");
myListener.onCallback = function() {
new Scale(mc).run(100,100,2000,Sine.easeIn);
}
Example 7: (Example.swf) (Example.swf)
To animate many movieclips the same way, this class also accepts
an Array of movieclips instead of one movieclip. This way yields to a better performance than
creating a new class instance for each movieclip you want to animate. Different
start values of your movieclip properties are considered when animating multiple movieclips
within one animation instance.
The following example is meant to shows that different start values are considered. 50 rectangles will be drawn with the drawing package and scaled with Scale using multiple animations within one animation instance. See .swf example above.
var target:Line = new Line(500,0,500,98.5);
target.draw();
var squares:Array = new Array();
for (var i:Number = 0; i<50; i++) {
var x:Number = Math.random() 300;
var w:Number = Math.random() 300;
var myRectangle:Rectangle = new Rectangle(0, i2, 100, 1);
myRectangle.setRegistrationPoint({x:0, y:0});
myRectangle.lineStyle();
myRectangle.draw();
myRectangle.movieclip._xscale = w;
squares[i] = myRectangle.movieclip;
}
var myScale:Scale = new Scale(squares);
myScale.setOptimizationMode(true);
myScale.animationStyle(6000,Bounce.easeOut);
myScale.run(500,squares[0]._yscale);
The example below moves, scales and rotates a number of movieclips with different start values. See .swf example above.
var mcs:Array = new Array();
for (var i = 0; i<20; i++) {
var x:Number = Math.random() 640;
var y:Number = Math.random() 400;
var r:Number = Math.random() 360;
mcs[i] = this.attachMovie("mc", "mc"+i, i, {_x:x, _y:y, _xscale:0, _yscale:0, _rotation:r});
}
var myMove:Move = new Move(mcs);
myMove.animationStyle(8000,Sine.easeInOut);
myMove.run(320,200);
var myScale:Scale = new Scale(mcs);
myScale.animationStyle(8000,Sine.easeInOut);
myScale.run(100,100);
var myRotation:Rotation = new Rotation(mcs);
myRotation.animationStyle(8000,Sine.easeInOut);
myRotation.run(360);
Example 8: (Example.swf) A similar experiment like the above shows the speed difference compared to the way that animates each movieclip in a single instance. This is the slow way:
var squares:Array = new Array();
for (var i:Number = 0; i<200; i++) {
squares[i] = _root.attachMovie("square_mc", "s"+i, i, {_y:i2});
var myScale:Scale = new Scale(squares[i]);
myScale.scaleWithPixels(true);
myScale.setOptimizationMode(true);
myScale.animationStyle(10000,Bounce.easeOut);
myScale.run(550,squares[0]._height);
}
Example 9: (Example.swf) ...and this is the fast way:
var squares:Array = new Array();
for (var i:Number = 0; i<200; i++) {
squares[i] = _root.attachMovie("square_mc", "s"+i, i, {_x:0, _y:i2});
}
var myScale:Scale = new Scale(squares);
myScale.scaleWithPixels(true);
myScale.setOptimizationMode(true);
myScale.animationStyle(10000,Bounce.easeOut);
myScale.run(550,squares[0]._height);
usage:
var myScale:Scale = new Scale(mc);
var myScale:Scale = new Scale(mc, amountx, amounty);
var myScale:Scale = new Scale(mc, amountx, amounty, duration);
var myScale:Scale = new Scale(mc, amountx, amounty, duration, callback);
var myScale:Scale = new Scale(mc, amountx, amounty, duration, easing, callback);
var myScale:Scale = new Scale(mc, values);
var myScale:Scale = new Scale(mc, values, duration, callback);
var myScale:Scale = new Scale(mc, values, duration, easing, callback);
var myScale:Scale = new Scale(mcs);
var myScale:Scale = new Scale(mcs, amountx, amounty);
var myScale:Scale = new Scale(mcs, amountx, amounty, duration);
var myScale:Scale = new Scale(mcs, amountx, amounty, duration, callback);
var myScale:Scale = new Scale(mcs, amountx, amounty, duration, easing, callback);
var myScale:Scale = new Scale(mcs, values);
var myScale:Scale = new Scale(mcs, values, duration, callback);
var myScale:Scale = new Scale(mcs, values, duration, easing, callback);
parameters:
(MovieClip) Movieclip to animate.
(Array) Array of Movieclips to animate.
(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 AnimationCore class.
description: Scales a movieclip from its the current _xscale and _yscale or _width and _height property values to specified amounts in a specified time and easing equation.
usage:
myScale.run();
myScale.run(amountx, amounty);
myScale.run(amountx, amounty, duration);
myScale.run(amountx, amounty, duration, callback);
myScale.run(amountx, amounty, duration, easing, callback);
myScale.run(values, duration);
myScale.run(values, duration, callback);
myScale.run(values, duration, easing, callback);
parameters:
returns: void
description: similar to the run() method. Offers start and end parameters.
usage:
myScale.animate(start, end);
parameters:
returns: void
description: jumps to a specific step of the animation and stays there.
usage:
instance.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:
myInstance.animationStyle(duration);
myInstance.animationStyle(duration, callback);
myInstance.animationStyle(duration, easing, callback);
parameters:
returns: Void.
description: changes the scaling mode. Default is false. If true it scales the movieclip with _width and _height properties. If false it scales the movieclip with _xscale and _yscale properties.
usage:
myScale.scaleWithPixels(pixelscale);
parameters:
true or false.returns: void
description: Movieclips scale according to their registration point. If the registration point is in the center of the shape, the movieclip will scale evenly on all sides. setRegistrationPoint in Scale emulates modifying the registration point of the animation. Top left is 0,0. The parameter object accepts either x and y properties with coordinates as values of the registration point or a position property with String flags. Currently there are the following options for the position property available:
CENTER = central registration point of movieclip.
Example 1: Set the registration point of an mc to the upper left corner (0,0). So even if mc's registration point is in the center, it will scale like as if the registration point would be on the upper left corner.
var myScale:Scale = new Scale(mc);
myScale.setRegistrationPoint( {x:0,y:0} );
myScale.run(200, 200);
usage:
myInstance.setRegistrationPoint(registrationObj);
parameters:
returns: Void.
description: rounds animation results to integers. (might be usefull for animating pixelfonts). Default is false.
usage:
myInstance.roundResult(rounded);
parameters:
true rounds the result. Animates with integers. Less accuracy. false animates with floating point numbers.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 values of the current tween. _xscale and _yscale or _width and _height properties.
usage: myInstance.getStartValues();
returns: (Array) First value is _xscale or _width, second is _yscale or _height.
description: sets the original, starting values of the current tween. _xscale and _yscale or _width and _height properties.
usage: myInstance.setStartValues(startValues);
parameters:
returns: Boolean, indicates if the assignment was performed.
description: returns the targeted values of the current tween. _xscale and _yscale or _width and _height properties.
usage: myInstance.getEndValues();
returns: (Array) First value is _xscale or _width, second is _yscale or _height.
description: sets the targeted value of the current tween. _xscale and _yscale or _width and _height properties.
usage: myInstance.setEndValues(endValues);
parameters:
returns: Boolean, indicates if the assignment was performed.
description: returns the current values of the current tween. _xscale and _yscale or _width and _height properties.
usage: myInstance.getCurrentValues();
returns: (Array) First value is _xscale or _width, second is _yscale or _height.
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.
value (Array) values to animate.
usage:
myScale.addEventListener(event, listener);
myScale.addEventListener(event, listener, handler);
parameters:
returns: Void.
description: Removes a listener from a subscribed event.
usage:
myScale.removeEventListener(event, listener);
myScale.removeEventListener(event, listener, handler);
parameters:
returns: Void.
description: GDispatcher specific feature. Removes all listeners for a specific event, or for all events.
usage:
myScale.removeAllEventListeners();
myScale.removeAllEventListeners(event);
parameters:
returns: Void.
description: GDispatcher specific feature. Checks if a listener is already subscribed to a certain event.
usage:
myScale.eventListenerExists(event, listener);
myScale.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