0
votes

The current behavior of textField is to render all text as if it were HTML. Is there a way to tell the system that this is plain text, even if it looks like html?

In AS2 there was a .html property which I could set to false to get this behavior, bit it seems to have disappeared.

I'm well aware that I can html-escape the input to get the desired behavior, but I'm looking for the cleanest / simplest solution. (Also it seems that I'd have to write my own html-escape function...)

1
Which "textfield" class are you referring to? You mention TextField which is a native Flash player class (not Flex), but it looks like you are using Flex. The TextField class has an htmlText property, so my assumption was that it only rendered HTML if you used that property, and that you would get your desired effect simply by using TextField's text property. - Sunil D.
@SunilD. Sorry, I'm not clear on the difference between flex and flash. I thought they were interchangeable as far as I'm concerned. As to your suggestion, assigning to .text doesn't have the behavior you expect. The behavior is exactly the same as assigning to .htmlText. - bukzor

1 Answers

4
votes

The AS3 text field has two properties, text and htmlText. The text property can be used to display purely plain text, even if it looks like html. The two properties are automatically linked by Flash, so editing text will update htmlText and vice-versa.

You should be able to use the text property to achieve your goal. Unfortunately, if you are using a style sheet with your text field, both properties will be treated as HTML. In this case, you have two choices. You can perform the styling without a style sheet, using simple TextFormat objects, which may be simple if your stylesheet is not too complex. If you really need to use a stylesheet, you can take advantage of AS3's link between the two text properties to escape your text automatically.

For example, if you wanted to update a text field called tf which uses a style sheet, but you wanted plain text, you could do it like this:

var temp:TextField = new TextField();
temp.text = plainText;
tf.text = temp.htmlText;

The temporary text field will automatically generate escaped HTML, which you can then use in your actual text field.