Texfield Wrangling

30 Sep

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.

30 September 2005 at 1:59 am

8 Responses to Texfield Wrangling

  1. avatar photo
    ro 30 September 2005 at 3:22 am #

    Why use font tags? CSS is the way to go in all applications.

  2. avatar photo
    Jensa 30 September 2005 at 3:27 am #

    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.)

  3. avatar photo
    brandon ellis 30 September 2005 at 3:54 am #

    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.

  4. avatar photo
    Last ActionScript Hero 30 September 2005 at 8:35 am #

    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.


    Let me know if you are doing something different from what I am.

    -KP

  5. avatar photo
    Jensa 30 September 2005 at 3:14 pm #

    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…

  6. avatar photo
    Jensa 30 September 2005 at 3:43 pm #

    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 wink

  7. avatar photo
    Last ActionScript Hero 30 September 2005 at 11:39 pm #

    Glad that you sorted out the problem.

    Cheers,
    KP

  8. avatar photo
    chris pelsor 04 October 2005 at 5:22 am #

    I am available for birthdays, weddings, and bar mitzvahs… wink

  9.