I am trying to round off rotations to the neatest 90 degrees and then scale the transform items to fit to the left or right side of the stage. I know how to round off the rotations, but I can't seem to get the positioning and the scaling right (because the x and y values change after the rotation).
Here is the code I am using:P
private function rotateAroundCenter (ob:*, angleDegrees:Number, ptRotationPoint:Point):void {
var m:Matrix=ob.transform.matrix;
m.tx -= ptRotationPoint.x;
m.ty -= ptRotationPoint.y;
m.rotate (angleDegrees*(Math.PI/180));
m.tx += ptRotationPoint.x;
m.ty += ptRotationPoint.y;
ob.transform.matrix=m;
}
private function scaleToFit($side)
{
var itemAbsRotation:Number = Math.abs(tItem.targetObject.rotation);
var rotateNum:Number = 0;
var ptRotation:Point = new Point(_currRollOver.width/2, _currRollOver.height/2);
if(itemAbsRotation > 0 && itemAbsRotation < 135)
{
rotateNum = roundToNearest(90, itemAbsRotation);
}else if(itemAbsRotation > 134 && itemAbsRotation < 213)
{
rotateNum = roundToNearest(180, itemAbsRotation);
}else if(itemAbsRotation > 213 && itemAbsRotation < 45)
{
rotateNum = 0;
}
rotateAroundCenter(_currRollOver.targetObject, rotateNum,ptRotation);
if(imgInfo.type == "COLOR")
{
pX = _mainAppStage.x;
pY = _mainAppStage.y;
if($which == "left")
{
_currRollOver.width = _mainAppStage.width/2;
_currRollOver.height = _mainAppStage.height;
_currRollOver.x = pX;
_currRollOver.y = pY;
}else if($which == "right")
{
_currRollOver.width = _mainAppStage.width/2;
_currRollOver.height = _mainAppStage.height;
if(mirrorOffset == false)
{
_currRollOver.x = _mainAppStage.width/2 + _currRollOver.width/2 + 2;
_currRollOver.y = _mainAppStage.y;
}else
{
_currRollOver.x = _mainAppStage.width + _currRollOver.width/2;
_currRollOver.y = _mainAppStage.y;
}
}
}