How to strip HTML tags from text fields in ActionScript 2

When you use the variable name of a text field in Flash CS 6, CS 5.5 or CS 5 or any other version of Flash that uses ActionScrip 2, you’ll get HTML tags in the text, even with the ‘Render text as HTML’ option off.

The problem

You probably used the text field variable, which you can edit in the properties panel Variable field. After selecting the text field, you typed in a variable name in the options part of the Properties panel. When a user types in text, Flash adds HTML tags that can be tricky to get ride of. For example, if the user types in ‘Hello’, your variable will contain ‘<TEXTFORMAT LEADING=”5″><P ALIGN=”LEFT”><FONT FACE=”Arial” SIZE=”12″ COLOR=”#000000″ LETTERSPACING=”0″ KERNING=”0″>Hello</FONT></P></TEXTFORMAT>’

The solution

properties of a textfield in Flash CS6A simple solution for this, is to use the Properties instance name instead. For example, if your text field has the instance name ‘contact_name’, you can read the text that it contains by reading it’s .text property. For example: trace(contact_name.text);

Geef een reactie