Actionscript:如何旋转文本字段?

发布于 2024-07-27 12:18:18 字数 283 浏览 4 评论 0原文

如何在 ActionScript 3.0 中旋转文本字段? 一旦我更改文本字段的旋转属性,它就不会显示。

例如:

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);

How do you rotate a text field in actionscript 3.0? As soon as I change the rotation property of the text field, it does not display.

for example:

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

水晶透心 2024-08-03 12:18:18

为了查看旋转的文本,您必须嵌入字体。

In order to see rotated text, you'll have to embed the font.

不再让梦枯萎 2024-08-03 12:18:18

另一种方法是,使用 BitmapData::draw 将文本字段复制到 BitmapData,然后创建包含结果的位图,并添加该结果到显示列表,而不是原始的 TextField ...

这有一个很大的优点,即您不需要嵌入字体,这会减少 swf 文件大小...OTOH,您将失去所有TextField` 的交互性,并且 swf 在播放时需要更多 RAM,但后者并不太重要......

为了使文本看起来平滑,请将 Bitmap::smoothing 设置为 true ...此外,如果您以更高分辨率渲染图像,它也会有所帮助...伪抗锯齿,可以这么说...绘制文本时,传递一个 Matrix< /code> 放大 2 倍并缩小 Bitmap 2 倍...这样看起来会更好...

greetz

back2dos

an alternative is, to copy the textfield into a BitmapData using BitmapData::draw and then creating a Bitmap containing the result, and adding that one to the display list, instead of the original TextField ...

this has the great advantage, that you don't need to embed the font, which reduces swf filesize ... OTOH, you will lose all of the TextField`'s interactivity, and the swf will need more RAM when playing, but the latter is not too significant ...

for the text to look smooth, set Bitmap::smoothing to true ... also, it helps, if you render your image at a higher resolution ... pseudo-anti-aliasing, so to speak ... when drawing the text, pass a Matrix scaled up by factor 2 and scale down the Bitmap by factor 2 ... that way it'll look better ...

greetz

back2dos

深白境迁sunset 2024-08-03 12:18:18

支持 Christophe Herreman 的更多信息:ActionScript - 旋转文本

Some more info supporting Christophe Herreman : ActionScript - Rotating Text

咋地 2024-08-03 12:18:18

我只是想将我的经验添加到这个问题中。 我也想旋转文本。

起初,我仅使用 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 时,文本都会消失。 最后我屈服了,使用 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 的情况下做到这一点,请分享!

I just wanted to add my experience to this question. I too wanted to rotate text.

At first, I embedded the font using only 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...

But every time I set embedFonts = true, the text would disappear. Finally I gave in and embedded the font using Flash.

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

It finally worked.

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);

Oh how I loathe using the Flash IDE for anything. If anyone was able to do this without using Flash, please do share!

洋洋洒洒 2024-08-03 12:18:18

这对我有用。

在 CS5 中,我需要更改“字体嵌入”对话框中的设置才能使其正常工作。

要显示“字体嵌入”对话框,请单击“字符”面板中的“嵌入”按钮,或双击库中的字体符号。

然后,选择您希望能够旋转的字体并单击“Actionscript”选项卡。

最后,选中导出为 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 将旋转应用于该字段,我仍然可以看到字体。

This is what worked for me.

In CS5, I needed to change a setting in the Font Embedding dialog box for it to work.

To show the Font Embedding dialog, either click the Embed button in the Character panel, or double-click a Font symbol in the Library.

Then, select the font you want to be able to rotate and click the Actionscript tab.

Finally, check the Export for Actionscript checkbox. Leave the defaults and click OK.

Below is the code that I used:

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);

If then then apply rotation to that field via AS, I still see the font.

哑剧 2024-08-03 12:18:18
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);
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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文