Skip to main content
Participating Frequently
August 11, 2010
Answered

Retaining Bold and Italics in .txt

  • August 11, 2010
  • 1 reply
  • 4739 views

I think what I'm about to ask is impossible, but I wanted to run it by the experts first to be sure.

I  have a .doc file. I want to load the text from that file into Flash. So  I convert it into a .txt using a website like this one: http://apps.phplivedocx.org/convert/doc-to-txt.  I add in the little code at the beginning (myTextField=) and then Flash  loads it fine. The only problem is any marked up text (italics, bold,  underline) is lost. Is there any way to prevent this from happening? Or  for Flash to load text from something other than a .txt? Or to manually  reinsert html tags to the .txt and get Flash to understand them? Or  something else I'm not considering?

My text field correctly displays the text in the "PrimaryText.txt" file.  The first line of the text shows like this: <b>Testing this  text</b> instead of just showing up bold. And the "Render text as  HTML" is checked. Thanks in advance.

This topic has been closed for replies.
Correct answer Ned Murphy

doc files are rich text files that can have all kinds of text formatting applied in them.  txt files are simple ascii text files that only contain text and do not have any formatting for the text.

To get your bold text to appear when you use html tags and set the html property of the TextField to true (or choose the render as html option in the properties panel), you need to assign the text to the textfield using the htmlText property instead of the text property...

txt.text = "<b>Bold</b> text"; // displays <b>Bold</b> text

txt.htmlText = "<b>Bold</b> text";  // displays Bold text

(ps - please don't crosspost:  it's a courtesy that saves people from unnecessarily posting responses, which I probably just did)

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 11, 2010

doc files are rich text files that can have all kinds of text formatting applied in them.  txt files are simple ascii text files that only contain text and do not have any formatting for the text.

To get your bold text to appear when you use html tags and set the html property of the TextField to true (or choose the render as html option in the properties panel), you need to assign the text to the textfield using the htmlText property instead of the text property...

txt.text = "<b>Bold</b> text"; // displays <b>Bold</b> text

txt.htmlText = "<b>Bold</b> text";  // displays Bold text

(ps - please don't crosspost:  it's a courtesy that saves people from unnecessarily posting responses, which I probably just did)

CowAttackAuthor
Participating Frequently
August 11, 2010

Sweet. Thanks. It was just that one small line. Sorry about the cross post. I don't usually do that but when I posted something in the main Flash forum the person responding said he didn't know AS2, so I moved the post over here.

Ned Murphy
Legend
August 11, 2010

You're welcome