Copy link to clipboard
Copied
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?
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.
Copy link to clipboard
Copied
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";
Copy link to clipboard
Copied
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??
Copy link to clipboard
Copied
is my_txt a textarea component or a textfield?
Copy link to clipboard
Copied
It's a normal dynamic textfield drawn on stage. You can download the .fla file at http://sharesend.com/b4dzqkgr.
Copy link to clipboard
Copied
then either use the code i suggested or if you need to specify a font family, you'll need to embed that font with actionscript which is a multi-stop process.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
With me it doesn't. As you can see in attached image. The code is exactly the same. The text in the textfield drawn on stage is replaced by the string but font size is the same it was originally. It doesn't turn into 10pt. Did you try the file in the link I mentioned?
Copy link to clipboard
Copied
your file's corrupted. did you try unzipping it?
Copy link to clipboard
Copied
Zipped it again. Can you open is from this url? http://pastelink.me/dl/774278
Copy link to clipboard
Copied
yes.
you're correct. setNewTextFormat() doesn't work when assigning htmlText. it works when assigning text.
to format htmlText, use setTextFormat() after the htmlText is assigned.
Copy link to clipboard
Copied
Tried that to by moving the setTextFormat line in that last file, but same result: the text is replaced but stays 30pt in size where it should turn into 10pt. Can you test it on the pastelink file?
my_textArea.html = true;
my_textArea.htmlText="This is a test";
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.size = 10;
my_textArea.setNewTextFormat(myTextFormat);
Copy link to clipboard
Copied
no, use setTextForamt() after text is assigned:
my_textArea.html = true;
my_textArea.htmlText="This is a test";
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.size = 10;
my_textArea.setTextFormat(myTextFormat);
Copy link to clipboard
Copied
Ok, that indeed worked. Now if I could only get the bold tags work. For example, take this code:
my_textArea.html = true;
my_textArea.htmlText="This is <b>a test</b>";
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.size = 60;
myTextFormat.font = 'Eurocomic';
my_textArea.setTextFormat(myTextFormat);
I've imported both the regular and bold version of the the Eurocomic font. In this case I set the font being Eurocomic, hoping that the text between the bold tags would turn bold as I've imported both regular and bold versions of the font. But as it is now it shows the line as fully 'regular'. Shouldn't it be possible to use bold tags in a html textfield as long as I embed all versions of a font and embed them correctly?
Copy link to clipboard
Copied
you need to embed both fonts and use something like:
var tfor_reg:TextFormat = new TextFormat();
tfor_reg.size = 20;
tfor_reg.font = "reg";
var tfor_bold:TextFormat = new TextFormat();
tfor_bold.size = 30;
tfor_bold.font = "Bold";
my_textArea.html = true;
my_textArea.embedFonts = true;
my_textArea.htmlText = "This <b>is</b> a test";
my_textArea.setTextFormat(0,5,tfor_reg);
my_textArea.setTextFormat(5,10,tfor_bold);
my_textArea.setTextFormat(10,tfor_reg);
Copy link to clipboard
Copied
Though that does work, it's nowhere near practical! For each text in a textfield I would have to calculate from character x to character y which I would like to have bold and which in regular style!
My point being, after importing the fonts into the Library and embedding them that way, shouldn't it automatically pick up on the bold tags wherever I place them? Choosing the regular version of the font on normal text and the bold version for text between bold tags? As long as both versions belong to the same font?
Copy link to clipboard
Copied
use a stylesheet.