January 07, 2004

A funny thing about rendering html in text fields

I make a lot of chat apps with flash. Lobby chats, one on one chats, group chats, presentation chats... in the end they are really the same thing I guess and whenever I make a chat I start with a text box on the stage. I then press the little "render as HTML" button in the properties window (gotta have colors and sizes and links and stuff), and proceed to put in my code and run it.

Here's the problem. Everytime the chat starts from the second line in the text box, not the first line, so there is a weird one line space at the top. But only in the beginning. Since this annoyed me I used to solve the problem by initializing the app with a chat_txt.text=""; and the line feed would go away and it would be normal again. But this didn't go well with me and I was really looking for a way to find out why or how I could not have this happen.

It turns out, if you have a text object on the stage and you press the little icon to render it out to html, a line of html code automatically gets put in the text box. It has a

in it and this causes a line feed and gives me my problem. Though, if you set the text field to normal again, and go to the actions panel and enter chat_txt.html=true; it doesn't put the line feed in, and the text object is rendered out as html. This is the proper way it should work... Is it a bug? Don't know, and since it's only FlashMX then I'm sure nobody really cares, but I'm quite curious if the same problem (problem? or is it supposed to act like this?) happens in flashMX2004. If I'm the last guy on this earth to actually realize something so basic then so be it, but I'm sure there are a couple of you going "really? hmm"... or something along those lines :)

Posted by Graeme at January 7, 2004 09:51 AM
 



Comments

Hi Graeme,

I can't reproduce this with Flash MX or Flash MX 2004. Does this only happen when you're working with data from Flashcom? Can you give me 1-2-3 steps to see this in Flash MX with a simple string? Thanks.

Posted by: Vera at January 7, 2004 10:47 AM

Hi Vera,

1. Make a text box on the stage, dynamic with multiple lines or not..

2. Give it a name like chat_txt

3. Click the "render as html" button.

4. go to the actions panel and type in chat_txt.htmlText+="My text is this";

5. run it :)

Doing that compared with setting the html with AS shows different ouputs in the text. ps.. I'm using the Japanese version. Does it make a dif?

Posted by: Graeme at January 7, 2004 10:57 AM

Also, if you trace out the contents of the chat_txt.htmlText you will get a whole line of html code. Whereas if you set it by AS, nothing comes up in that trace.

Posted by: Graeme at January 7, 2004 11:37 AM

Hmmm. I didn't realize I had to do +=. A simple = does not cause this behavior. Also, this seems to have been fixed in Flash MX 2004.

One thing to watch out for in Flash MX 2004 is that all undeclared strings by default have a value of undefined. So

someVar += "this is the text";

would result in a string of "undefinedthis is the text".

Posted by: Vera at January 7, 2004 02:46 PM

Good to hear it's fixed. A simple = doesn't cause the behaviour because you are overwriting what is already in there. That is why I did (up until yesterday) chat_txt.text=""; But, I don't want to overwrite the text everytime somebody makes an entry in the chat, or we would have only one line chats... ;)

On your last note there, wouldn't that only be for variables and not my situation above where I am adding text into a text box that is on the stage? I hope I'm not understanding you wrong.

Thanks for the checking though. I was going to have a friend check the text thing FMX2004 but now I know!

Posted by: Graeme at January 7, 2004 04:46 PM

Yes, what I described is only true for variables. But I'm sure that a lot of developers assign the string to a variable first and then to the text field property. :)

Because of the "undefined" issue though I still think it's a bad idea to initiate a text field value with +=. I'm not saying use = every time and wipe out what's there :), just initiate the text field once with a =, then add to it with +=.

Posted by: Vera at January 8, 2004 12:26 AM

Thanks for the info Vera! When I update to MX2004, I'll make sure to initiate to reduce the chance of errors.

Posted by: Graeme at January 8, 2004 10:07 AM