我使用下面的從右上角旋轉文本域,我想知道找到右上角的最佳方式。找到右上角的旋轉文本域
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;
編輯:
我只是寫了這個測試在閃IDE下面的代碼(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;
您需要更具體一些,您是否需要「過去是右上角的當前位置」?你是否總是將盒子翻轉-45°或者你是否需要任何旋轉的一般解決方案? – 2011-03-10 15:20:18
好的,我很抱歉,我想總是得到txt TextField的右上角,不管旋轉角度是什麼,我需要使用trig來做到這一點嗎? – Neil 2011-03-10 15:32:49