2009-07-13 84 views
6

你如何在ActionScript 3.0旋轉文本字段?只要我改變文本字段的旋轉屬性,它不會顯示。的ActionScript:如何旋轉文本字段?

例如:

var txtFld:TextField = new TextField(); 
txtFld.x = 100; 
txtFld.y = 100; 
txtFld.width = 300; 
txtFld.height = 300; 
txtFld.text = "Test String"; 
txtFld.rotation = 90; 
addChild(txtFld); 

回答

8

爲了看到旋轉的文本,你必須嵌入字體。

5

一個替代方案是,使用BitmapData::draw然後創建一個Bitmap包含結果複製文本字段成BitmapData,和添加的一個到顯示列表,而不是原始TextField ...

這有很大的好處,你不需要嵌入字體,這減少了SWF文件大小... OTOH,你將失去所有的TextField的交互性,而SWF播放時將需要更多的RAM,但後者不太顯著...

爲文本看起來光滑,設置Bitmap::smoothingtrue ...它也有幫助,如果您在更高的分辨率渲染您的圖像...僞抗鋸齒,可以這麼說...繪製文本時,路過因子2按比例提高Matrix和因子2按比例縮小Bitmap ...這樣,它會更好看......

格爾茨

back2dos

0
var txtFld:TextField = new TextField(); 
txtFld.x = 100; 
txtFld.y = 100; 
txtFld.width = 300; 
txtFld.height = 300; 
txtFld.text = "Test String"; 

txtFld.embedFonts = true; // to embed the font ... now roation works 

txtFld.rotation = 90; 
addChild(txtFld); 
1

我只是想將我的經驗添加到這個問題。我也想旋轉文字。

首先,我只使用ActionScript嵌入字體。

Embed(source="C:\\WINDOWS\\Fonts\\CALIBRI.TTF", fontFamily="Calibri")] 
public static const FONT_CALIBRI:Class; 
... 
var font:Font = new Global.FONT_CALIBRI as Font; 
//Font.registerFont(Global.FONT_CALIBRI); //I tried various other things... 

但是每次我設置embedFonts = true時,文字就會消失。最後我給了和embedded the font using Flash

var font:Font = new FontClass as Font; //FontClass was exported from Flash IDE 

它終於奏效了。

var textFormat:TextFormat = new TextFormat(font.fontName); 

textField = new TextField(); 
textField.defaultTextFormat = textFormat; //must be before setting the text 
textField.embedFonts = true; //needed to rotate fonts 
textField.autoSize = TextFieldAutoSize.CENTER; 
textField.antiAliasType = flash.text.AntiAliasType.ADVANCED; 
textField.text = ("TESTING") 
this.addChild(textField); 

哦,我討厭使用Flash IDE的任何東西。如果有人能夠在不使用Flash的情況下做到這一點,請分享!

1

這是對我工作。

在CS5中,我需要更改字體嵌入對話框中的設置才能使用。

要顯示字體嵌入對話框,請單擊字符面板中的嵌入按鈕,或雙擊庫中的字體元件。

然後,選擇您想要旋轉的字體並單擊Actionscript選項卡。

最後,選中Export for Actionscript複選框。保留默認值,然後單擊確定。

下面是我使用的代碼:

textField = new TextField(); 
textField.autoSize = TextFieldAutoSize.LEFT; 
textField.embedFonts = true; 

format.font = "Arial"; // Or whatever the name of your font is in the embed dialog 
format.size = 24; 
textField.defaultTextFormat = format; 

addChild(textField); 

如果然後再通過AS應用旋轉那場,我還看到字體。