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

 

senocular.com ActionScript Library

frameRotate.as

Name: frameRotate() - For 3D animations, goes to and stops on correct frame given rotation
Author: senocular: www.senocular.com
Date: 1899-12-31T00:48:17.900
Documentation:
Movieclip FRAMEROTATE: plays a movieclip through
its frames based on passed rotation.  Best used with
3D rendered spins or photographic QTVR Objects.

Arguments:
- r: (rotation) - a value in degrees (360 degrees in one rotation) to "spin" the
desired clip.
 
Setup:
- Simply have your frames of rotation in a single movieclip (which this prototype is
used on). The code assumes a clockwise rotation and uses 0 degrees for frame 1. This can
be something to take note of when importing your animation though could just as well be 
adjusted through negating or adding on to the passed rotation value. AlsO, don't include
any extra frames in the movieclip as the _totalframes are used in the calculation.

Example:
// moveiclip with a rendered rotation
onClipEvent(enterFrame){
	this.frameRotate(rotate += 5, 180);
}

1
2
3
4
5
6
7
MovieClip.prototype.frameRotate = function(r){
	r %= 360;
	if (r < 0) r += 360;
	r = Math.round(this._totalframes * r/360);
	r %= this._totalframes;
	this.gotoAndStop(r+1);
}