Question

i have one swf which looks like below image enter image description here

OBJECTIVE:-want to rotate the red colored line swf along center as per given image enter image description here

i have conditions like

x-axis,y axis,x=1,x=y,x=-y

my first two conditions are shown in the images. for the next three conditions the images are enter image description here enter image description here enter image description here

Was it helpful?

Solution

You can do this either with a matrix translation and rotation, or by finding the objects center, rotating the object, and then translating it back (which is basically the same thing as the matrix technique).

The matrix way:

var mat:Matrix = spr.transform.matrix;
var bounds:Rectangle = spr.getBounds( spr.parent );
mat.translate( -(bounds.left + bounds.width/2), -(bounds.top + bounds.height/2 ) );
mat.rotate( degree * Math.PI / 180 ); //rotate amount
mat.translate( bounds.left + bounds.width/2, bounds.top + bounds.height/2 );
spr.transform.matrix = mat;

Without matrix:

var bounds:Rectangle = spr.getBounds( spr.parent );
var center:Point = new Point( bounds.x + bounds.width/2, bounds.y + bounds.height/2 );

spr.rotation = degree; //rotate amount

bounds = spr.getBounds( spr.parent );
var newCenter:Point = new Point( bounds.x + bounds.width/2, bounds.y + bounds.height/2 );
spr.x += center.x - newCenter.x;
spr.y += center.y - newCenter.y;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top