Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

pScale.as

Name: pScale() - Percentage scale: scales a clip proportionally almost as if going back in the distance
Author: senocular: www.senocular.com
Date: 1899-12-31T00:30:35.000
Documentation:
MovieClip PSCALE: scales a clip proportionally by a 
percent allowing for a consistant scaling factor from an
incrimental value.  A similar effect is given by altering the
scale continuously by a percentage rather than a constant
value. The more the movieclip is scaled in this manner, the
less effect the scaling will seem to have.
 
Arguments:
- move: the movement in the virtual distance the clip travels.  This is more or less
the new scale of the clip. A positive number scales down (away or outward) where
as a negative number scales up (towards or inwards).  Outwards scales less and less as
move increases.  Inwards scales greater as move increases (or rather decreases as it is
negative).
- factor: (optional) the factor from (0-100) at which each value of movement scales. The 
lower the factor the slower the scale. Default is 1 which with at a movement of 1, will
reduce a 100% scaled clip by 1 and consecutively less thereafter.
- xscale and yscale: (optional) base scales from which the scaled clip is to be ... based.

Example:
// steadily scale a clip down (as if moving away)
// clip will never reverse itself from negative scaling
// as would _xscale-- and _yscale-- would
onClipEvent(enterFrame){
	pScale(scaleBy++);
}

1
2
3
4
5
6
7
8
MovieClip.prototype.pScale = function(move, factor, xscale, yscale){
	if (arguments.length == 1) var factor = .99;
	else factor = Math.max(0, (100-Math.abs(factor))/100);
	if (arguments.length < 3) var xscale = 100, yscale = 100;
	var scaleBy = Math.pow(factor, move);
	this._xscale = xscale*scaleBy;
	this._yscale = yscale*scaleBy;
}