PDA

View Full Version : Multiple paragraphs and HTML text in AS3.0



dthought
May 3rd, 2007, 02:51 AM
Hi everyone,

'Tis my first post here on Kirupa. I've been coding in Flash since Flash 4's pre-ActionScript language, and whilst I pretty much had AS1.0 down pat and half-paid attention to AS2.0 where possible, AS3.0 is giving me a good chance to relearn a lot of stuff. Naturally, I'm running into problems.

At the moment, I'm battling with Text Fields, specifically with multiline paragraphed HTML text that is dynamically created. In my example, I create one TextField programmatically, and I have a second which I have placed, sized and named manually.

Here is my code:



import flash.text.TextField;
function testTextField ()
{
var myTextField:TextField = new TextField();

myTextField.htmlText = "<p><b>Paragraph 1</b></p><p>Paragraph 2</p>";
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.multiline = true;

stage.addChild(myTextField);
}
testTextField();
placedBox.htmlText = "<p>Paragraph 1</p><p>Paragraph 2</p>";


Unless I add in line breaks (\n\n) into the htmlText between the p tags, Flash will not break lines as expected. However, the htmlText for the placed text box works properly.

Am I missing something?

Cheers,

Mike

Dazzer
May 3rd, 2007, 04:32 AM
try <br>

?

devonair
May 3rd, 2007, 04:46 AM
try setting the wordWrap property and see if that helps..

myTextField.wordWrap = true;

dthought
May 3rd, 2007, 05:14 AM
Oh wait... I think I found it. If the htmlText comes before the property which enables multiline, then it does not allow multiline HTML.

However, if it comes after then all is well.

Thanks for your suggestions, it got me thinking about things :)