【问题标题】:Basic TextFormat change is doing nothing基本 TextFormat 更改无济于事
【发布时间】:2013-04-24 23:46:32
【问题描述】:

代码:

var BoldTextFormat:TextFormat = new TextFormat();
BoldTextFormat.bold = true;
weapons[player.activeWeapon].weaponName.defaultTextFormat = BoldTextFormat;

这看起来很简单,但它并没有做任何事情!文本根本没有变粗。

使用weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat); 也无济于事。

这些traces:

trace(weapons[player.activeWeapon].weaponName);
trace(weapons[player.activeWeapon].weaponName.defaultTextFormat);
trace(BoldTextFormat);

这个输出的结果:

[object TextField]
[object TextFormat]
[object TextFormat]

这是我要加粗的文本字段:

我已经嵌入了粗体:

可能有什么问题?没有没有错误。跟踪文本字段的文本显示正确的文本,所以这不是问题。

【问题讨论】:

  • 您要更改该字段中的文本吗?还是 TextField 中的默认文本?请在您实际更改文本的行中显示您的代码。
  • @prototypical 我更改了文本。它只是Weapon 的构造函数中的weaponName.text = theName

标签: actionscript-3 flash textfield textformat


【解决方案1】:

您可能需要嵌入粗体字体,您的图像显示“常规”字体。

好的,我发现了这里的魔力。它开始为您工作的可能原因是您实际上为您的字段设置了粗体。

但这就是魔法。在库中,右键单击粗体字体并选择属性。然后转到actionscript设置并启用:

为动作脚本导出

接下来,您需要在您的代码中添加这一行:

BoldTextFormat.font = "Times New Roman Bold";

应该可以的。

遗憾的是,TextFormat 的 .bold 似乎不会自动找到粗体版本。

【讨论】:

  • 好的,问题在于嵌入将大小设置为不同的作品。我会接受这个答案并提出一个新问题。
【解决方案2】:

试试:

 weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat);

defaultTextFormat适用于设置格式后添加的文本,如果要更改已设置文本的格式,则应使用setTextFormat

【讨论】:

  • 那么weapons[player.activeWeapon].weaponName 可能与您在属性窗格中显示的TextField 不同。
  • @proto 是的,它是。 @Baris 是的,追踪它的文字显示正确的文字
  • 在您的图像中,它不显示粗体,而是显示“常规”。你确定你有粗体嵌入吗?
  • 好的,问题在于嵌入将大小设置为不同的作品。我会赞成这个答案并提出一个新问题。
猜你喜欢
  • 2021-09-16
  • 2011-08-29
  • 2018-12-20
  • 2013-12-27
  • 2021-07-13
  • 2012-04-02
  • 1970-01-01
  • 1970-01-01
  • 2022-08-09
相关资源
最近更新 更多