以免自己再忘记。这里记下。有几种方案可选:
1
var m:Matrix = obj.transform.matrix;
var p:Point = m.transformPoint(new Point(obj.width/2, obj.height/2));
m.translate(-p.x, -p.y);
m.rotate(angle);
m.translate(p.x, p.y);
obj.transform.matrix = m;
m.translate(-p.x, -p.y);
m.rotate(angle);
m.translate(p.x, p.y);
obj.transform.matrix = m;
2
var transtimer:Timer=new Timer(50,150);
transtimer.addEventListener('timer',transtimerHandler);
transtimer.addEventListener('timerComplete',transComplete);
var objMatrix3:Matrix=flipbox3.flipobj3.transform.matrix;
var flipstep3:Number=Math.PI/2;
//取得物体长和宽的半值作为Matrix的tx 、ty值
var rX = flipbox3.width/2;
var rY = flipbox3.height/2;
transtimer.start();
function flip_v_3():void {
objMatrix3.tx-=rX;
objMatrix3.ty-=rY;
objMatrix3.rotate(flipstep3/100);
objMatrix3.tx+=rX;
objMatrix3.ty+=rY;
flipbox3.flipobj3.transform.matrix=objMatrix3;
}
function transtimerHandler(event:TimerEvent):void {
flip_v_3();
}
function transComplete(event:TimerEvent):void {
transtimer.reset();
transtimer.start();
}
3
package transformer{
import flash.display.DisplayObject;
import flash.geom.Point;
import flash.geom.Matrix;
/**
*
* @author Nodihsop
*/
public class TransformWithPoint {
public static function transformWithExternalPoint(displayOb:DisplayObject, regPiont:Point, angleDegrees:Number = 0, sx:Number = 1, sy:Number = 1):void
{//自身坐标系
var m:Matrix = displayOb.transform.matrix;
m.tx -= regPiont.x;
m.ty -= regPiont.y;
if (angleDegrees % 360 != 0) {
m.rotate(angleDegrees*(Math.PI/180));
}
if (sx != 1 || sy != 1) {
m.scale(sx,sy);
}
m.tx += regPiont.x;
m.ty += regPiont.y;
displayOb.transform.matrix = m;
}
public static function transformWithInternalPoint(displayOb:DisplayObject, regPiont:Point, angleDegrees:Number = 0, sx:Number = 1, sy:Number = 1):void
{//容器坐标系
var m:Matrix = displayOb.transform.matrix;
regPiont = m.transformPoint(regPiont);
m.tx -= regPiont.x;
m.ty -= regPiont.y;
if (angleDegrees % 360 != 0) {
m.rotate(angleDegrees*(Math.PI/180));
}
if (sx != 1 || sy != 1) {
m.scale(sx,sy);
}
m.tx += regPiont.x;
m.ty += regPiont.y;
displayOb.transform.matrix = m;
}
}
}
TransformWithPoint.transformWithInternalPoint(sp,new Point(100,100),90)
TransformWithPoint.transformWithExternalPoint(sp,new Point(50,50),90)
4
建一个外部容器,让其00点对准要旋转的图片中心。把要转的图片昨天那个外部容器的子容器,这样每次转外部容器,那个图片就转了。