Texfield Wrangling
Textfields in Flash are not all they could be to say the least. Today I spent 2 hrs trying to debug an application that does funky things to HTML in textfields. My conclusion this far: Flash is actually changing what I set the htmlText property to just as it pleases. No matter what SIZE I use in the FONT-tags, Flash will replace whatever my size with it's own number - 11.
I'm inputting this HTML:
<P ALIGN="LEFT">
<FONT FACE="Helvetica, Arial, sans-serif" SIZE="18" COLOR="#000000" LETTERSPACING="0" KERNING="0">
<B>dcfg fdsgfd sgfdsgf ds</B>
</FONT>
</P>
For some reason this turns into this:
<P ALIGN="LEFT">
<FONT FACE="Helvetica, Arial, sans-serif" SIZE="11" COLOR="#000000" LETTERSPACING="0" KERNING="0">
<B>dcfg fdsgfd sgfdsgf ds</B>
<FONT SIZE="18">
</FONT>
</FONT>
</P>
Notice the font-tag at the end. My size info moved there? Anybody ever experienced something similar?
PS: if you think the HTML look ugly (non standard), this is the only kind of HTML that Flash is using. Capital letters on all tags and less than standard sizing to say the least.
Comments
Why use font tags? CSS is the way to go in all applications.
Posted by: ro | September 29, 2005 10:22 PM
If you just want to display some HTML, CSS is the way to go. If you want to edit the textfield, you can't use that approach. Once you apply a stylesheet to a textfield - you cannot edit it...
(I'm working on a CMS-system and this is for the WYSIWYG editor.)
Posted by: Jensa | September 29, 2005 10:27 PM
ugh. I feel your pain. I went through that hell last spring and since have tried to not use content injection into a Flash textfield unless I have absolutely no other choice. I seriously believe that the html rendering is the weakest feature in Flash. Good luck.
Posted by: brandon ellis | September 29, 2005 10:54 PM
Hi Jensa,
I tried your example in Flash 8 with four different dynamic text fields but I am not able to see Flash changing the font size. I dont have Helvetica so the font getting used is Arial.
I had two sets of textfields one dynamic and one static to compare the results and both look alike. I am assuming you used trace(mytext.htmlText) to see what's Flash is using.
You can see what I tried out here: http://www.lastashero.com/images/test1.swf
Let me know if you are doing something different from what I am.
-KP
Posted by: Last ActionScript Hero | September 30, 2005 03:35 AM
Hi ASH,
Thanks for testing! I'll also get the same results if I rip out just that single bit. I could try to elaborate a bit? My Flash-based CMS (the one we use on Flashmag) has several input-fields. Each field is attached to an object so that I can tuck some extra variables for each field.
The text-field renders fine when I use the WYSIWIG editor and also when I save the data. When the save is complete, the CMS re-renders what was saved in the servers database. Every object is kept, but the textfields attached to the objects are removed and recreated to prevent other kids of bugs. The text displays briefly at the right size, but is then magically converted to 11 pixels. I'm not doing anything in the CMS after the initial proper display. Only one of 8 classes in the app knows about the existance of the textfields and there's no running scrips that could trigger any redrawing of any of those text-fields. If I reload the SWF, it all displays as it should. I've tried commenting out every block of code happening after the loading, but to no vain...
Posted by: Jensa | September 30, 2005 10:14 AM
Ahhhrg! Chris dropped by and helped me debug a bit. We found the bug and truly - it wasn't Flash's fault. If you've worked with selections on textfields, you'll probably know that if you click a button, you'll loose your selection. The way around this is to implement a focus-fixer-routine that keeps the correct object selected. This triggered upon reloading the text and set the previous selection to the first style in a dropdown wich was size 11...
Oh well. Every copy of Flash should come with a pair of "fresh eyes" that can look at your code when you're tired ;)
Posted by: Jensa | September 30, 2005 10:43 AM
"Every copy of Flash should come with a pair of "fresh eyes" that can look at your code when you're tired ;)" - That's a good feature request for Flash 9 :)
Glad that you sorted out the problem.
Cheers,
KP
Posted by: Last ActionScript Hero | September 30, 2005 06:39 PM
I am available for birthdays, weddings, and bar mitzvahs... ;)
Posted by: chris pelsor | October 4, 2005 12:22 AM