Harnessing dynamic text fields

I don’t know about anyone else but I find controlling the appearance of dynamic text (when the source is located outside of Flash) is a frustrating task.

Maybe I’m the only one out here still using good 'ol HTML forms but they have thier advantages. Personally I find them a little easier to maintain and they can speak many languages unknown to Flash. Don’t get me wrong, I love virtually every aspect of Flash :slight_smile: however, the point I’m trying to make here is that I am using an HTML form to update a database, which is the information source for a dynamic text field inside my SWF.

The form is fairly simple in that it consists of a select field, a textarea and a submit button. Essentially the form allows the user to update the contents of a column in the database and save any changes they want made. This is a fairly simple process using a some PHP and PHP-generated JavaScript but the tough, or confusing, part lies in conserving the formatting of the text. I’m sure by now you’re thinking of using addslashes() and or str_replace() to get rid of unwanted characters, and that’s good. But what about carriage returns? Have you ever used loadVaribles() to load external data into a dynamic text field? You should notice that even if Flash is told to render text as HTML, it, unlike true HTML, will render carriage returns as a &ltP&gt tag. I know this sounds absurd but it’s true. Go ahead and give it a shot. On the other hand, if you refrain from using any carriage returns and either insert a &ltBR&gt tag or just let text wrap in the textarea, your SWF will display the breaks as single line breaks (using CR, Flash will insert a &ltP&gt tag resulting in a double-space effect). Great, simple work-around. The downside is that to get text that breaks in a suitable fashion (i.e. perssing enter), the user is given two options: either insert a &ltBR&gt tag or wait till the line is full so that your text wraps. In fact, this would result in a rather drab writing experience. Imagine having to write a long document (such as this…) and having to insert a &ltBR&gt after each line that didn’t reach the edge of the textarea! Boy that would make me sick… Maybe I’m just lazy but I’ve recently discovered an effective work-around that would allow one to write normal, script-sterile documents.

Using PHP, one can make good use of the str_replace() function to simply replace all “\r”, or carriage return, characters with “&ltBR&gt”. When you put the resulting string into a text file, or database column, Flash will read it properly, putting only a single space between lines.

Phew that was long… I hope someone else has been having this same problem as it would mean there was a point to writing this! Heheh…

Anyways, don’t hesitate to give your feedback on the overall usefulness/uselessness of this document. I apreciate it all.