Changing Selection Color on Dynamic TextFields

For some reason or another selection color is not an option on dynamic TextFields in Flash.
This has been one of those issues that I’ve just accepted up until now.

I’m currently working on a project that has a design featuring white text over a black background. The caveat was that the text needed to be selectable as well. As anyone working with selectable text knows, the selection color is always black. This posed a problem… the user couldn’t actually tell when the text was selected or what characters were actually selected. I remembered a while ago reading about applying a color transform to the text field to change the selection color. Only problem with that solution is that it applies the transform to the entire field as a whole, which means the text color and background color are affected by the transform as well.

I played around with this solution for quite a while and came up with a fairly reliable way of changing the selection color and maintaining the text and background colors that you initially chose. There are still some hiccups, but so far this is the best solution that I’ve found. First download the SelectionColor class and then test it with:

Now, this works with many color choices, but it is not a full proof solution. I have seen certain colors, depending on the colors chosen, not work out exactly as expected. If anyone notices anything in the code that could be perfected let me know and I will post an update. This seems to be one of those annoying things about Flash that would be nice to have a solid solution.

About the author

Mark

View all posts

20 Comments

  • Excellent Post! I’m new to flash/flex/actionscript and this is something I’ve been wondering about.

    Out of curiosity have you ever had to deal with selecting text across multiple TextField objects? Seems like it should be built into the Flash functionality, but I’ve found when I put two TextFields on the screen (via actionscript) I can’t select the text from both of them. Any thoughts on how this is supposed to be accomplished in flash?

  • Great post mate. I found this exceptionally useful for a recent project I had to do, really saved me alot of time. Keep up the good work! 🙂

  • Hi !

    Sounds great..

    But I’m still working with AS2 & Flash 8 and ColorTransform doesn’t have a color property. Only a rgb property.

    Do you think it’s customizable for AS2 ? 😉

    Thx for response (great blog anyway..)

    Fro

  • Hey Mark,

    I used the method you devised to change the selection color of a text field in flash 8. I have been able to use it with windows. Thanks for the post. However, while testign the code on Mac OSX, I found that it doesn’t work. I tried couple of options but it did not work. Can you please check for this? This would be a great help. Thanks a lot.

    Daljit

  • Yeah definatly something lots of us would like to know how to do… with ease!

    Im surprised to have such a hardtime finding out how, when this very effect is used in the Flash Help display!

  • 1. put a transparent text
    2. you can get the end and beginning of the selected text, using this info you can draw under the text field boxes of the size and color you want.
    3. If you use scrolling text then you need further calculations to position the hilight box correctly

  • Hi everyone,
    I suggest only one little modification (sorry for my bad english), in order to be able to easly reset the color transform of a textfield. (For exemple when a same textField is use on both black and white background)

    I added a little function in the class:

    public static function resetColorTransform( field:TextField ):void
    {
    var colorTrans:ColorTransform = new ColorTransform();
    }
    Thank you for all !

  • Hi!

    Thanks for this useful class.

    I noticed a limitation: when the sprite containing the textfield is cacheAsBitmap, the coloring doesn’t work.

    Any chance it could be done for cached DisplayObjects?

  • there has a bug . If add a blurFilter(0,0) to textField for fadeIn/fadeOut.

    It don’t work well with this.

    filters=[new BlurFilter(0,0)]

Leave a Reply

Your email address will not be published. Required fields are marked *