Skip to main content
Inspiring
April 19, 2013
Answered

change font size textfield drawn on stage

  • April 19, 2013
  • 1 reply
  • 2539 views

I've place a dynamic textfield on stage with some fake text in it and gave it the instance my_textArea. Now I want to change the font size so I've used this code:

 

var myTextFormat:TextFormat = new TextFormat();

myTextFormat.size = 10;

my_textArea.setTextFormat(myTextFormat);

my_textArea.html = true;

my_textArea.htmlText="This is a test";

But it doesn't resize the text. It changes it to 'This is a test', but the font size is exactly the same as it was originally (30).

It does work when I create the textfield through actionscript, but I also want to apply it to a dynamic textfield which I've already placed on stage.

What am I doing wrong?

This topic has been closed for replies.
Correct answer kglad

As you can see in the fla file, I've embedded both Times New Roman fonts. The regular and bold version. The code you suggested doesn't work. It only works when using normal text. Not when I'm using htmlText and set html to 'true'. But then of course bold tags don't work. Perhaps it's not possible to use textFormat with htmlText?


the code i suggested works.  just replace your code with the code i suggested.  don't change anything.

and again, if you're going to use the code in your message #2, you need to (correctly) embed both fonts and you'll need to use setTextFormat with two textformat instances or use a stylesheet.

1 reply

kglad
Community Expert
Community Expert
April 19, 2013

use setNewTextFormat to apply a textformat to a textfield's future text.  use setTextFormat to apply a textformat to a textfield's already assigned text:

var myTextFormat:TextFormat = new TextFormat();

myTextFormat.size = 10;

my_textArea.setNewTextFormat(myTextFormat);

my_textArea.html = true;

my_textArea.htmlText="This is a test";

jiggy1965Author
Inspiring
April 19, 2013

Doesn't work either. Tried it with this code:

var my_fmt:TextFormat = new TextFormat();

my_fmt.bold = true;

my_fmt.font = "Times New Roman";

my_fmt.color = 0xFF9900;

my_fmt.size = 15;

//

my_txt.wordWrap = true;

my_txt.html=true;

my_txt.multiline = true;

my_txt.border = true;

my_txt.setNewTextFormat(my_fmt);

my_txt.htmlText = "Oranges are <b>a good source</b> of vitamin C";

Used in on a textfield already on stage with a fake text of 30pt size. Two things happen:

With above code the dummy text stays 30pt in size and the bold tags are processed showing 'a good source' in bold characters. The text stays black.

When I comment the my_txt.html-trye line the code does work. Text changes to orange and 10pt. The bold tags are ignored however and show as normal characters.

How can I make both work? That the text already inside the textfield is changed to the new line, in orange, shrunk to 10pt and with the bold tags working??

kglad
Community Expert
Community Expert
April 19, 2013

is my_txt a textarea component or a textfield?