PDA

View Full Version : Scaling and Rotating Image from center


illicit2k1
08-11-2008, 05:23 AM
Hey what would be the best way to scale and rotate an image using the center as an anchor point? This is for flex 3, the image is loaded from a webserver using the Loader class.

illicit2k1
08-11-2008, 09:09 PM
figured this out, using a matrix, first translate to (-imgwidth/2, -imgheight/2) then do your .rotate() and then .scale(), then apply the matrix. for the loader i used loaderObj.content.transform.matrix = m;

karaczono
12-10-2010, 06:59 AM
I have been looking how to do that one and half hours, and nothing. Lot of different opinions on forums but not of them were working. At last I got it.


If you have a movie clip You have to open it and then set his x and y position for 0. Then you have to subtract from x position half of its width and from y position half of its height.

For example.

My circle_mc is 60px width and 60px heigth.

So I open my circle_mc and set its x for -30 and y for - 30.

If I would like to rotate it now it will be rotating around its central axis.


Here's a code: ;)

var myTimer : Timer = new Timer(30);
var speed = 0;
var switchOf = 1;

function rotateIt(event:TimerEvent):void
{
if(switchOf == 1)
{
speed++;
mc.rotationY += speed;
trace(speed);

if(speed >= 50)
{
switchOf = 0;
}
}
else
{
speed--;
mc.rotationY += speed;
trace(speed);

if(speed <= 1)
{
switchOf = 1;
}
}
}
myTimer.addEventListener(TimerEvent.TIMER, rotateIt);

myTimer.start();





The conclusion is that central axis is there where a inner x and y poins of an object are