August 2007 Archives
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:
package
{
import com.digitalflipbook.text.SelectionColor;
import flash.display.Sprite;
import flash.text.TextField;
/**
* The SelectionColorTest class runs a simple test changing a TextField selection color.
*
* @author Mark Walters
* @since 2007.08.13
*/
public class SelectionColorTest extends Sprite
{
public function SelectionColorTest()
{
var tf:TextField = new TextField();
this.addChild( tf );
tf.width = 180;
tf.height = 20;
tf.text = "Here's some text to try selecting.";
tf.background = true;
tf.backgroundColor = 0x000000;
tf.border = true;
tf.borderColor = 0x000000;
tf.textColor = 0xFFFFFF;
SelectionColor.setFieldSelectionColor( tf, 0xD3D3D3 );
}
}
}
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.