无法显示动态文本 AS3
Cannot display dynamic text AS3
我创建了一个名为 "abc"
的动态文本。我想显示像 "testing"
这样的文本,但我什么也没得到。真是一片空白。
这是我的脚本:
abc.text = "testing";
您应该嵌入 字体。它应该有效。
如果您使用的是 Flash Professional,请转到菜单选项卡 Text -> Font Embedding
那么 windows 将被反对。你应该 select 你的字体,给它一个名字然后在 字符范围 你可以 select all 现在点击还行
和 VOILA....... :)
希望这有助于...
我不确定您当前的编程经验,但您需要创建 TextField
class 的新实例并使用 addChild()
函数。 TextField
class 的所有实例默认为 dynamic
首先您需要创建 TextField
的实例并设置其文本:
//Creates a new instance of the TextField class with the name newText
var newText:TextField = new TextField();
//Sets the text of the newText
newText.text = "testing";
为了更改某些内容,例如字体大小或对齐,您还 需要创建 TextFormat class 的实例。您需要将新文本的格式设置为您创建的格式并根据您的喜好进行调整:
//Creates a new instance of the TextFormat class
var newFormat:TextFormat = new TextFormat();
//Scales the format to the font size 24
newFormat.size = 24;
//Sets the newText's format to the format you created
newText.defaultTextFormat = newFormat;
最后,为了查看显示字段中的文本,您必须简单地使用 addChild()
函数:
//Adds the newText TextField to the stage so you can see it
stage.addChild(newText);
所以这是完成的代码:
//Creates a new instance of the TextField class
var newText:TextField = new TextField();
//Creates a new instance of the TextFormat class
var newFormat:TextFormat = new TextFormat();
//Scales the text to the font size 24
newFormat.size = 24;
//Sets the newText object's format to the format you created
newText.defaultTextFormat = newFormat;
//Sets the newText object's text to "testing"
newText.text = "testing";
//Adds the newText TextField to the stage so you can see it
stage.addChild(newText);
如果您愿意,可以查看 TextField and TextFormat 参考文献以了解您可以调整的所有其他内容(例如颜色、抗锯齿类型等,但我不会涵盖所有这些)。
虽然这段代码有一些小问题。您最好创建一个适合您需要的自定义 class(我称之为我的文本),并且您还需要 嵌入 您的文本,这样一台计算机就不会不支持您在程序中使用的文本无论如何都可以看到它。有一个方便的教程,但不幸的是我不能 link 一次超过 2 个东西,但如果你只是搜索 "AS3: Text Fields and Formats - Republic of Code" 它应该是第一个搜索结果。
我创建了一个名为 "abc"
的动态文本。我想显示像 "testing"
这样的文本,但我什么也没得到。真是一片空白。
这是我的脚本:
abc.text = "testing";
您应该嵌入 字体。它应该有效。
如果您使用的是 Flash Professional,请转到菜单选项卡 Text -> Font Embedding
那么 windows 将被反对。你应该 select 你的字体,给它一个名字然后在 字符范围 你可以 select all 现在点击还行
和 VOILA....... :)
希望这有助于...
我不确定您当前的编程经验,但您需要创建 TextField
class 的新实例并使用 addChild()
函数。 TextField
class 的所有实例默认为 dynamic
首先您需要创建 TextField
的实例并设置其文本:
//Creates a new instance of the TextField class with the name newText
var newText:TextField = new TextField();
//Sets the text of the newText
newText.text = "testing";
为了更改某些内容,例如字体大小或对齐,您还 需要创建 TextFormat class 的实例。您需要将新文本的格式设置为您创建的格式并根据您的喜好进行调整:
//Creates a new instance of the TextFormat class
var newFormat:TextFormat = new TextFormat();
//Scales the format to the font size 24
newFormat.size = 24;
//Sets the newText's format to the format you created
newText.defaultTextFormat = newFormat;
最后,为了查看显示字段中的文本,您必须简单地使用 addChild()
函数:
//Adds the newText TextField to the stage so you can see it
stage.addChild(newText);
所以这是完成的代码:
//Creates a new instance of the TextField class
var newText:TextField = new TextField();
//Creates a new instance of the TextFormat class
var newFormat:TextFormat = new TextFormat();
//Scales the text to the font size 24
newFormat.size = 24;
//Sets the newText object's format to the format you created
newText.defaultTextFormat = newFormat;
//Sets the newText object's text to "testing"
newText.text = "testing";
//Adds the newText TextField to the stage so you can see it
stage.addChild(newText);
如果您愿意,可以查看 TextField and TextFormat 参考文献以了解您可以调整的所有其他内容(例如颜色、抗锯齿类型等,但我不会涵盖所有这些)。
虽然这段代码有一些小问题。您最好创建一个适合您需要的自定义 class(我称之为我的文本),并且您还需要 嵌入 您的文本,这样一台计算机就不会不支持您在程序中使用的文本无论如何都可以看到它。有一个方便的教程,但不幸的是我不能 link 一次超过 2 个东西,但如果你只是搜索 "AS3: Text Fields and Formats - Republic of Code" 它应该是第一个搜索结果。