I know this sounds like a really obvious question, but it's proving harder to figure out than I thought. I'm developing in Flash 8/ActionScript 2.0.
我知道这听起来像是一个非常明显的问题,但事实证明它比我想象的要难。我正在开发Flash 8 / ActionScript 2.0。
I have a label component, and I'm dynamically assigning it text from an xml document. For example:
我有一个标签组件,我正在动态地从xml文档中分配它。例如:
label.text = "<b>" + xml_node.firstChild + "</b>";
This successfully changes the label's text to whatever is in that XML node, and since I enabled HTML, it makes it bold. However, I want to increase the size of the label's font, and using <font>
tags won't work.
这成功地将标签的文本更改为该XML节点中的任何内容,并且因为我启用了HTML,所以它使其变为粗体。但是,我想增加标签字体的大小,使用标签将无法正常工作。
Am I missing something? How do I make the font larger? ActionScript is just so picky!
我错过了什么吗?如何使字体变大? ActionScript非常挑剔!
4 个解决方案
#1
2
When you say "label component", do you mean a Flex 2 label, or a TextField?
当您说“标签组件”时,您的意思是Flex 2标签还是TextField?
In the latter case, the font tag should work just fine. will set the font to 24px text for example. If it doesn't, you can use the stylesheet class to specify a font size and then assign it to the TextField.
在后一种情况下,字体标记应该可以正常工作。例如,将字体设置为24px文本。如果没有,您可以使用样式表类指定字体大小,然后将其分配给TextField。
In the case of of Flex 2 label, use label.setStyle("fontSize", 24) to set it to 24px text for example.
对于Flex 2标签,请使用label.setStyle(“fontSize”,24)将其设置为24px文本。
#2
1
Thanks for everyone's input! After reading David Arno's post, I figured it out. Here's what I was doing.
感谢大家的投入!在读完David Arno的帖子后,我发现了它。这就是我在做的事情。
label.text = "<b><font size=24>" + xml_node.firstChild + "</font></b>";
Here's what works:
这是有效的:
//note the 'single quotes' around the 24
label.text = "<b><font size='24'>" + xml_node.firstChild + "</font></b>";
I just tried different ways of typing 24 in there, and the single quotes worked. Also, don't forget to set HTML to true from the label's Parameters tab.
我只是尝试了不同的方式在那里键入24,单引号有效。另外,不要忘记从标签的“参数”选项卡中将HTML设置为true。
#3
0
I can't say for sure but I think you probably need to set the fontSize style of the Label.
我不能肯定地说,但我认为您可能需要设置Label的fontSize样式。
#4
0
The font tag will really only work if you have a web ready font like Arial, Verdana, or Times New Roman and even then it's still kinda goofy. A lot of times AS will usually just ignore the font tag, at least that's what I've run into. If you want to format your text I'd use the TextFormat class to manipulate your text instead of trying to set it through HTML tags. Unless you're setting the HTML tags because it's really being formatted with CSS?
如果你有像Arial,Verdana或Times New Roman这样的网络就绪字体,那么字体标签真的只会起作用,即便如此它仍然有点傻。很多时候AS通常只会忽略字体标记,至少这是我遇到过的。如果要格式化文本,我会使用TextFormat类来操作文本,而不是尝试通过HTML标记设置它。除非你设置HTML标签,因为它实际上是用CSS格式化的?
In that case I'd go through and make absolutely sure that your textfield is set up for HTML tags. Instead of using label.text I would try to use label.htmlText? It really could be any number of issues...
在这种情况下,我会通过并确保您的文本字段设置为HTML标记。我会尝试使用label.htmlText而不是使用label.text?它真的可以是任何数量的问题......
#1
2
When you say "label component", do you mean a Flex 2 label, or a TextField?
当您说“标签组件”时,您的意思是Flex 2标签还是TextField?
In the latter case, the font tag should work just fine. will set the font to 24px text for example. If it doesn't, you can use the stylesheet class to specify a font size and then assign it to the TextField.
在后一种情况下,字体标记应该可以正常工作。例如,将字体设置为24px文本。如果没有,您可以使用样式表类指定字体大小,然后将其分配给TextField。
In the case of of Flex 2 label, use label.setStyle("fontSize", 24) to set it to 24px text for example.
对于Flex 2标签,请使用label.setStyle(“fontSize”,24)将其设置为24px文本。
#2
1
Thanks for everyone's input! After reading David Arno's post, I figured it out. Here's what I was doing.
感谢大家的投入!在读完David Arno的帖子后,我发现了它。这就是我在做的事情。
label.text = "<b><font size=24>" + xml_node.firstChild + "</font></b>";
Here's what works:
这是有效的:
//note the 'single quotes' around the 24
label.text = "<b><font size='24'>" + xml_node.firstChild + "</font></b>";
I just tried different ways of typing 24 in there, and the single quotes worked. Also, don't forget to set HTML to true from the label's Parameters tab.
我只是尝试了不同的方式在那里键入24,单引号有效。另外,不要忘记从标签的“参数”选项卡中将HTML设置为true。
#3
0
I can't say for sure but I think you probably need to set the fontSize style of the Label.
我不能肯定地说,但我认为您可能需要设置Label的fontSize样式。
#4
0
The font tag will really only work if you have a web ready font like Arial, Verdana, or Times New Roman and even then it's still kinda goofy. A lot of times AS will usually just ignore the font tag, at least that's what I've run into. If you want to format your text I'd use the TextFormat class to manipulate your text instead of trying to set it through HTML tags. Unless you're setting the HTML tags because it's really being formatted with CSS?
如果你有像Arial,Verdana或Times New Roman这样的网络就绪字体,那么字体标签真的只会起作用,即便如此它仍然有点傻。很多时候AS通常只会忽略字体标记,至少这是我遇到过的。如果要格式化文本,我会使用TextFormat类来操作文本,而不是尝试通过HTML标记设置它。除非你设置HTML标签,因为它实际上是用CSS格式化的?
In that case I'd go through and make absolutely sure that your textfield is set up for HTML tags. Instead of using label.text I would try to use label.htmlText? It really could be any number of issues...
在这种情况下,我会通过并确保您的文本字段设置为HTML标记。我会尝试使用label.htmlText而不是使用label.text?它真的可以是任何数量的问题......