许多 SWF、嵌入单一字体,而不通过 Actionscript 创建文本字段?

发布于 2024-12-27 23:46:34 字数 798 浏览 5 评论 0原文

是否可以将字体嵌入到单个 SWF 中以便在许多其他 SWF 中使用,同时保持通过 Flash IDE 在这些 SWF 中进行所有文本排列和设置的能力?

我知道我可以从外部 SWF 检索字体、注册它并在新的 TextField 中使用它。不过,如果我不必在代码中创建每个文本字段,那就太好了。

例如,以下是加载包含某种字体的 SWF 并使用该字体的名称调用以下命令后的结果:

Font.registerFont();

原始文本字段不会显示任何内容,而新创建的文本字段使用原始文本字段则完美显示美好的。

        var format:TextFormat = onStageTextField.getTextFormat();

        onStageTextField.embedFonts = true;
        onStageTextField.defaultTextFormat = format;
        onStageTextField.text = "My Text";

        var newTextField:TextField = new TextField();
        newTextField.width = 300;
        newTextField.embedFonts = true;
        newTextField.defaultTextFormat = format;
        newTextField.text = "My Text";
        contentMC.addChild(newTextField);

Is it possible to embed a font in a single SWF to be used throughout many other SWFs, while maintaining the ability to do all the text arrangement and setup through the Flash IDE in those SWFs?

I know I can retrieve a font from an external SWF, register it, and use it in a new TextField. However it would be nice if I didn't have to create every text field in code.

For instance, the following is after loading in a SWF that has a font in it and calling the following using the name of that font:

Font.registerFont();

The original text field will show nothing, while the newly creating one USING THE FORMAT FROM THE ORIGINAL, shows perfectly fine.

        var format:TextFormat = onStageTextField.getTextFormat();

        onStageTextField.embedFonts = true;
        onStageTextField.defaultTextFormat = format;
        onStageTextField.text = "My Text";

        var newTextField:TextField = new TextField();
        newTextField.width = 300;
        newTextField.embedFonts = true;
        newTextField.defaultTextFormat = format;
        newTextField.text = "My Text";
        contentMC.addChild(newTextField);

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

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

发布评论

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

评论(1

〃温暖了心ぐ 2025-01-03 23:46:34

我担心你的主要问题的简短答案是“不”。有多种方法可以通过 IDE 将字体嵌入到代码中,但我不知道有什么方法可以实现您所描述的混合方法。

另一种方法:

在主 FLA 中创建 MovieClip,其中包含要在 IDE 中重用、设置样式和嵌入的每种样式的文本字段(或文本字段组)。将子 TextFields 命名为“txt”之类的名称。提供 MC 链接 ID。现在,当您加载子 SWF 时,创建并创建使用 flash.utils.getDefinitionByName() 为需要显示的任何文本字段添加 MC 实例。更新每个实例中的文本,如下所示:myMC.txt.text =“my text”。

上面的内容应该适用于许多领域的动态文本。当你说“文本排列”时......你是在谈论换行符调整吗?

I fear the short answer to your main question is "no." There's ways to embed font with code, and through the IDE, but I don't know of a way to do a hybrid approach like you describe.

An alternative approach:

In your main FLA Create MovieClips holding each style of textfield (or groups of textfields) you want to reuse, style and embed in the IDE. Name the child TextFields something like "txt". Give the MCs linkage ids. Now when you load your child SWF, create & add instances of the MCs for any textfields you need to display using flash.utils.getDefinitionByName(). Update the text in each instance like so: myMC.txt.text = "my text".

The above should work well for dynamic text in lots of fields. When you say "text arrangement"... are you talking about line-break adjustment?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文