Actionscript 3 查找旋转文本字段的右上角

Actionscript 3 查找旋转文本字段的右上角,actionscript-3,matrix,transform,Actionscript 3,Matrix,Transform,我使用下面的方法从右上角旋转文本字段,我想知道找到右上角点的最佳方法 var txt:TextField = new TextField(); txt.autoSize = TextFieldAutoSize.LEFT; txt.htmlText = "Some text here>"; mtx = txt.transform.matrix.clone(); Matri

我使用下面的方法从右上角旋转文本字段,我想知道找到右上角点的最佳方法

           var txt:TextField = new TextField();
            txt.autoSize = TextFieldAutoSize.LEFT;
            txt.htmlText = "Some text here>";


            mtx = txt.transform.matrix.clone();
            MatrixTransformer.rotateAroundInternalPoint(mtx, txt.width, 0, -45);
            txt.transform.matrix = mtx;
编辑:

我刚刚在FlashIDE中编写了下面的测试代码(omg,它会伤害…),显然库中有一个名为Arial的嵌入式字体。我无法将圆圈正确定位在文本字段的右上角

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;

如果您的意思是在转弯前右上方是什么:

// The field's original top right corner:
var localPoint:Point = new Point( txt.width, 0 );
var globalPosition:Point = txt.localToGlobal( localPoint );
如果您的意思是,在打开字段之后:

// The top right after being turned -45°
var localPoint:Point = new Point( txt.width, txt.height );
var globalPosition:Point = txt.localToGlobal( localPoint );
编辑:

好的,在看了你的测试之后,我尝试了很多东西,我想我发现了一些有用的东西:

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;
如果我运行这个,我会得到一个文本字段,旋转-45度,一个绿色的球粘在过去的右下角。我不知道你的MatrixTransformer类,但它应该能够处理任何矩阵


尝试复制并粘贴此代码,并对其进行修改,直到得到所需的结果。

感谢您的回复,这似乎无法在旋转版本上完成工作,似乎指向边界框的右下角,而不是旋转版本的右上角textfield@Neil,您确定第一个代码段不起作用吗?无论当前的旋转或位置是什么,它都应该为您提供右上角的全局位置。您确定您使用的是实际的textfield实例本身作为txt.localToGlobal的“txt”部分,而不是holder DisplayObject吗?Eyeeem,我在上面添加了一个测试,除非我缺少一些我无法让它工作的内容。@Neil我刚刚编辑了我的答案,请尝试新代码。它看起来非常脆弱,所以按1:1复制。例如,如果省略local3DtoGlobal行,则整个文本字段将消失。。。嘿,干得好,伙计,我发现只要调整Vector3D中的值,我就可以瞄准我想要的任何零件。谢谢你的坚持。你需要更具体一点,你需要“过去右上角的当前位置”吗?您是否总是将框旋转-45°,或者是否需要任何旋转的一般解决方案?好的,我很抱歉,无论旋转角度是什么,我都希望始终获得txt文本字段的右上角,是否需要使用trig?