2009-07-13 87 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应用旋转那场,我还看到字体。