views:

3222

answers:

4

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.

I have a label component, and I'm dynamically assigning it text from an xml document. For example:

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.

Am I missing something? How do I make the font larger? ActionScript is just so wonky!

A: 

I can't say for sure but I think you probably need to set the fontSize style of the Label.

Simon
+1  A: 

When you say "label component", do you mean a Flex 2 label, or a 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.

In the case of of Flex 2 label, use label.setStyle("fontSize", 24) to set it to 24px text for example.

David Arno
A: 

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?

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...

vanhornRF
A: 

Thanks for everyone's input! After reading David Arno's post, I figured it out. Here's what I was doing.

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.

Matt S