View comments | RSS feed

_rotation (MovieClip._rotation property)

public _rotation : Number

Specifies the rotation of the movie clip, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range; for example, the statement my_mc._rotation = 450 is the same as my_mc._rotation = 90.

Availability: ActionScript 1.0; Flash Player 4

Example

The following example creates a triangle movie clip instance dynamically. When you run the SWF file, click the movie clip to rotate it.

this.createEmptyMovieClip("triangle", this.getNextHighestDepth());

triangle.beginFill(0x0000FF, 100);
triangle.moveTo(100, 100);
triangle.lineTo(100, 150);
triangle.lineTo(150, 100);
triangle.lineTo(100, 100);

triangle.onMouseUp= function() {
    this._rotation += 15;
};

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth() method.

See also

_rotation (Button._rotation property), _rotation (TextField._rotation property)


Version 8

Comments


Creator MF said on Nov 25, 2005 at 6:18 PM :
When using actionscript to put movieclips dynamicly on stage I've learned different techniques here. At this point I was wondering if there is a way to reflect movieclips using Actionscript. Knowing there is _rotation property, is there a _flip property or a technique to achieve flip horizontal or vertical?

Good job macromedia team ... livedoc is a lifesaver!
djtechwriter said on Dec 9, 2005 at 2:51 PM :
To replicate "flipping" a movie clip in ActionScript, you need to apply a Matrix to the movie clip. For example, the following "flips vertically" a movie clip instance "my_mc":
import flash.geom.Matrix;
var myMatrix:Matrix = new Matrix(1, 0, 0, -1, my_mc._x, my_mc._y);
my_mc.transform.matrix = myMatrix;

Read more about the Matrix class here: http://livedocs.macromedia.com/flash/8/main/00002389.html
No screen name said on Dec 16, 2005 at 8:20 PM :
Is there a way to set the pivot point(center of rotation circle) for the movie clip so that it rotates around that, instead of the default, which currently seems (0, 0).
--thank you
No screen name said on Dec 19, 2005 at 10:53 AM :
note, this property is still in degrees, while all of the Math routines are in
radians!

why macromedia, why??
Fumio Nonaka said on Jan 16, 2006 at 12:12 AM :
[Wrong]:
Values outside this range are added to or subtracted from 360 to obtain
a value within the range

[Correct]:
A multiple of 360 are added to or subtracted from values outside this
range to obtain a value within the range

var _mc:MovieClip = this.createEmptyMovieClip("my_mc", 1);
_mc._rotation = 810;
trace(_mc._rotation); // 90 = 810-360*2
_mc._rotation = -270;
trace(_mc._rotation); // 90 = -270+360
djtechwriter said on Jan 26, 2006 at 1:56 PM :
Re: setting the "pivot point" or registration point for rotation... No. There is currently no way to change the registration point (0,0) in ActionScript.
toyfoo said on Mar 28, 2006 at 1:16 AM :
to rotate around a point other than the center:
http://chattyfig.figleaf.com/mailman/htdig/flashcoders/2003-July/082026.html
Bill O said on Jul 18, 2006 at 10:49 AM :
I was coding out a compass and was running into trouble with the reporting of a movie clip's own rotation. It was reporting negative rotation for anything with a a rotation over 180 degrees (181 degrees would be reported as -179 degrees) - this behavior is clearly spelled out in the documentation.

Anyway, I was converting strings retrieved from an XML source for compass direction ( N, S, E, W, SSE, SE, ESE, etc. ) to numbers using a switch clause. So N=0, E=90, S=180, W = 270, etc. (fill in the blanks).

To get my rotation to evaluate correctly for a full range of 360 degrees, I came up with this function:

function rot360(theRot:Number) {
//if the number is negative
if (theRot<0) {
/*add it to 180 to get the difference, then add 180 to get the true compass reading*/
var convNum:Number = (180+theRot)+180;
// 360 degrees on a circle is equal to 0 degrees! This should never happen but if it somehow does, convert it to 0 - this line is optional.
if (convNum == 360) {
convNum = 0;
}

} else {
//if it's not negative, it must be positive (or 0), so the converted number is equal to the number submitted to the function
var convNum:Number = theRot;
}
//return the converted number
return convNum;
}

/*function use - converts the reported rotation of targetMC to a number between 0 and 359.99.... depending on the number that is evaluated*/

var trueRot:Number = rot360(targetMC._rotation);

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002511.html