Very stupid (I hope) question on ActionScript and Dynamic Text

Too embarrassing for the dedicated expert forums…

Is there anything better than the replaceText function for replacing substrings? Ideally, something that does the replacement before it’s in a text area?

I’m trying to replace, say, a [i ] (from an xml file) with <i>, so that when it does show up in a textfield that renders as html, I get italic text.

replaceText doesn’t work… even though the textarea renders as HTML, I get
<i>text</i>.

I’ve never heard of "ActionScript " or “Dynamic Text”. But …

A true html <textarea> object cannot support any fancy formatting. Everything in there is interpretted as (& displayed as) raw characters. Specifically, the content is NOT interpretted as HTML, so things like <i>, etc. don’t work in them.

There are alternate script-based or ActiveX-based input areas which support at least some embedded formatting. Switching to one of those may solve your problem.

But trying to stuff HTML into a <textarea> is a 100% dead end.

p.s.
When I first read your post I missed the point that you were trying to format inside a <textarea>. I thought you were trying to apply formatting to dynamically generated results in general. On that basis I wrote what follows. It may be irrelevant, but since I spent the time, maybe it’ll be helpful to you or to somebody else. …

The fact you’re seeing the markup like <i>text</i> pretty well proves the output is being html-encoded after you’re done with it.

if you’re not familiar with the term, “html-encoding” is a protective technique used by websites to prevent people from inserting malicious html or script into the results. Unfortunately, it can’t tell the difference between safe things like italics and evil things, so it simply prevents all html in the output.

It works like this: instead of sending “less-than i greater-than” to the browser which would interpret it as a signal to begin italics, the website sends “special-symbol-that-means-display-a-less-than-character i special-symbol-that-means-display-a-greater-than-character”, and the browser displays “<i>”.

And if the website is configured to apply that correction after you provide the response to it, there’s no way for you to control or counteract that behavior through the results you provide.

These things can be hard to write about on a messageboard because it too is protecting itself by html-encoding what you & I enter.
I’m assuming these tools are something you’re using on some public site like facebook, etc. If so, you’re stuck; the webmaster wants to ensure you cannot put html in your results and that’s that.

If these are tools you’re using on a website you completely control, then there might be an 'advanced" option to turn off html-encoding. Given the habit of modern consumer software to make itself “easy” to use by never using any scary (read: “technically accurate”) terms for the options, you may have a hard time finding the option you need. “Enable html”, “enable script”, or “enable unsafe output” might be examples of the terminology they’d use.

What is the context in which you’re using ActionScript?

Thanks… I should have been more clear about that.

I was using ActionScript to display text data from an XML file in a Flash movie. This was going fine, until I realized that some of the text needed to be italic.
With something like:
<message>This is a message<message> all went well.
But this, of course, would not be interpreted:
<message>This is a <i&gtmessage</i> which unfortunately has a child node within the node I want to display.</message>

To solve that problem, I planned to use square brackets instead of angle brackets (sound familiar?), and then use basic string handling to turn the square bracket italic tags into proper html tags. This would then be posted into a Flash text area.

Which brought me to where I was last night. Problem:

  1. ActionScript’s string handling isn’t much better than Excel’s, and it took me an hour to even find out about one built-in function that would do what I needed. And that function can only act on a string once it’s in a text area; nothing seems to be available for handling a string that’s stored as a variable.
  2. Once text is posted into a dynamic text area, if HTML tags are added, they will not be interpreted literally.

I worked it out, though.
Solution:

  1. Do the replaceText on a dynamic text area that’s off the stage.
  2. Then set the target dynamic text area to the value of the offstage text area.

I should have said more of what I’m writing here last night. Lesson learned, I guess, is to never post while I’m tearing my hair out and sleep on it first. Thanks to LSLGuy for the informative post, though… and I’d still be interested to know if ActionScript has any better string handling functions.
2.

This is why I asked the question. The only place I’ve heard of ActionScript is within the context of Flash, where any text becomes part of the binary code for the movie fed into the player. The browser doesn’t parse for HTML tags in the text of a Flash movie any more than it does the text in a JPEG image.

But I figured maybe ActionScript has moved beyond flash into page scripting and I just wasn’t aware.

You actually don’t need to change any of the brackets to another bracket type & replace anything - you can have html inside your XML.

In your XML field you are using for your text coming in wrap your html with a CDATA tag:

<nodename><![CDATA[Not bolded<br><b>Bolded stuff</b>]]></nodename>
Then on your text field use the htmlText property to set your html into the variable - and you won’t need to replace any tags.

Eg.) if the instance name of your Dynamic text field is myText (not the Var field - the instance name must be set).
myText.htmlText=node_result;

Also - here is an oldie but a goody on converting html with entities of lt and gt for the tags into html in flash dynamic text field:



//Hide the text field & bring data from server into the myText field as htmlText
myText._alpha=0;
myText.htmlText = myDataFromServer;
//get the new text with tags
tmpVar = myText.text;
//set the text field blank
myText.text ="";
//Now show the text field again & set the html to the converted text
myText._alpha=100;
myText.html=true;
myText.htmlText =tmpVar;