views:

574

answers:

2

Hi I am working on actionscript 3 which I have to use translation rotation scaling to a movieclip. I have the rotation and scaling working properly but when I dealing with translation I find the problem that the translation will move the object outside of the origin so when I wanted to rotate the object, the object no longer rotate as expected. What is the best way to implement the translation so that it translate the movieclip while translate the origin....

Last thing.. What is the difference between movieclip.scale and movieclip.transform.scale function? If i use movieclip.scale, do I still able to get the movieclip.transform.matrix from that movieclip.scale

+2  A: 

All matrix transformations, including rotation and scale, take effect relative to the origin of the co-ordinate system where the clip lives. If you want to rotate or scale around any other point, you should translate the clip to that point, transform, and translate back. In other words, this:

clip.rotation = 30;

does the same thing as this:

var tx:Number = clip.x;
var ty:Number = clip.y;
var m:Matrix = clip.transform.matrix;
m.translate( -tx, -ty );
m.rotate(30*Math.PI/180);
m.translate( tx, ty );
clip.transform.matrix = m;

It works exactly the same way with scale transformation.

For your other question, the difference between MovieClip.scaleX/Y and Matrix.scale is exactly the same as with rotate - you can apply your rotations either way, but with the built in MC properties they take effect relative to the clip's registration point, and the Matrix functions are relative to the origin. If the clip's registration point is at (0,0) then they work the same.

fenomas
A: 

A more complete answer for ActionScript 3.0 can be found here:

http://www.actionscript-flash-guru.com/blog/33-scale-around-a-point--transform-multiple-objects--actionscript-3-as3

The article focuses specifically on scaling an object from a static point and scaling multiple objects from that single static registry point.

Niko Limpika