Crazy,最近在學習flex的時侯,發現一件說重要也不是這麼重要的東西,各位Blog的朋友們,那就是寫一個Class來「旋轉TextField」的“撇步”,就是利用BitmapData來實作。
程式碼如下:
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class RotationTest extends Sprite
{
public function RotationTest()
{
var textfield:TextField = new TextField();
textfield.text = "Test";
var textFmt:TextFormat = new TextFormat();
textFmt.size = 100;
textFmt.align = "left";
textFmt.bold = true;
textFmt.font = "Arial";
textfield.setTextFormat(textFmt);
textfield.autoSize = TextFieldAutoSize.LEFT// TextField根據text調整大小
var bw:Number = textfield.width;
var bh:Number = textfield.height;
if(textfield.width>2880 )
{
textfield.scaleX *= 2880/textfield.width;//文字調整大小
bw = 2880;
}
if(textfield.height>2880)
{
textfield.scaleY *= 2880/textfield.height;
bh = 2880;
}
var myBitmapData:BitmapData = new BitmapData(bw, bh, true,0);
myBitmapData.draw(textfield);
var bmp:Bitmap = new Bitmap(myBitmapData);
bmp.x = 300;
bmp.y = 200;
bmp.rotation = 180;
addChild(bmp);
}
}