I am using the following to rotate a textfield from its top right corner, I would like to know the best way to find the point of the top right corner.
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.htmlText = "Some text here>";
mtx = txt.transform.matrix.clone();
MatrixTra开发者_如何转开发nsformer.rotateAroundInternalPoint(mtx, txt.width, 0, -45);
txt.transform.matrix = mtx;
EDITED:
I just written this test code below in the flash IDE (omg that hurts...), obviously there is an embedded font called Arial in the library. I can't get the circle to correctly position on the top right of the textfield.
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.geom.Matrix;
import flash.display.Shape;
import fl.motion.MatrixTransformer;
import flash.geom.Point;
import flash.text.TextFormat;
import flash.text.Font;
Font.registerFont(Arial);
var angle:Number = -45
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.embedFonts = true;
txt.defaultTextFormat = new TextFormat("Arial", 20, 0x0000ff);
txt.text = "Here is some text";
txt.border = true;
txt.x = 100;
txt.y = 100;
addChild(txt);
var circle:Shape = new Shape();
circle.graphics.beginFill(0x00ff00);
circle.graphics.drawCircle(-5, -5, 10);
circle.graphics.endFill();
addChild(circle);
var mtx:Matrix = txt.transform.matrix.clone();
MatrixTransformer.rotateAroundInternalPoint(mtx, txt.width, 0, angle);
txt.transform.matrix = mtx;
// The top right after being turned -45°
var localPoint:Point = new Point( txt.width, txt.height );
var globalPosition:Point = txt.localToGlobal( localPoint );
circle.x = globalPosition.x;
circle.y = globalPosition.y;
If you mean what was the top right before turning it:
// The field's original top right corner:
var localPoint:Point = new Point( txt.width, 0 );
var globalPosition:Point = txt.localToGlobal( localPoint );
If you mean, after having turned the field:
// The top right after being turned -45°
var localPoint:Point = new Point( txt.width, txt.height );
var globalPosition:Point = txt.localToGlobal( localPoint );
EDIT:
Ok, after seeing your test I experimented with a bunch of things and I think I found something that will work:
var angle:Number = -45
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.defaultTextFormat = new TextFormat("Arial", 20, 0x0000ff);
txt.text = "Here is some text";
txt.border = true;
txt.x = 100;
txt.y = 250;
stage.addChild(txt);
var local3d:Vector3D = new Vector3D( txt.width, txt.height );
var circle:Shape = new Shape();
circle.graphics.beginFill(0x00ff00);
circle.graphics.drawCircle(-5, -5, 10);
circle.graphics.endFill();
stage.addChild(circle);
var mtx:Matrix = txt.transform.matrix.clone();
mtx.rotate( -45 / 180 * Math.PI );
txt.transform.matrix = mtx;
var globalPosition:Point = txt.local3DToGlobal( local3d );
circle.x = globalPosition.x;
circle.y = globalPosition.y;
If I run this, I get a TextField, turned -45 degrees with a green ball stuck to what-used-to-be-the-bottom-right corner. I don't know your MatrixTransformer class, but it should be able to work with any matrix.
Try and copy&paste this code and fiddle around with it until you get the result you want.
精彩评论