How to fix stupid flash player bug with a TextField`s selection color?

I think this code can help you:

package {
import flash.events.FocusEvent;

import mx.controls.ComboBox;
import mx.controls.NumericStepper;
import mx.controls.TextArea;
import mx.controls.TextInput;
import mx.core.Application;
import mx.core.UITextField;
import mx.styles.StyleManager;

public class TextInputSelector {

/*

USAGE:

<mx:TextInput
focusIn="TextInputSelector.tFin(event)"
focusOut="TextInputSelector.tFou(event)"
/>

*/

//setting up some vars for customization</code>
public static var fieldHighLight:Number = 0xFFFF00;
public static var fieldTextHighLight:Number = 0x000000;

public static function tFin(e:FocusEvent):void{
if (e.target is UITextField){

if (UITextField(e.target).owner is TextInput){
TextInput( UITextField(e.target).owner ).setStyle( "backgroundColor" , Number(fieldHighLight));
TextInput(UITextField(e.target).owner ).setStyle( "color", Number(fieldTextHighLight));
}

if (UITextField(e.target).owner is TextArea){
TextArea(UITextField(e.target).owner ).setStyle( "backgroundColor" , Number(fieldHighLight));
TextArea(UITextField(e.target).owner ).setStyle( "color" , Number(fieldTextHighLight));
}

if (UITextField(e.target).owner.parent is ComboBox){
ComboBox(UITextField(e.target).owner.parent ).setStyle( "backgroundColor" , Number(fieldHighLight));
ComboBox(UITextField(e.target).owner.parent ).setStyle( "color" , Number(fieldTextHighLight));
Application.application.callLater( function(e:FocusEvent): void{ UITextField(e.target).setSelection( 0 , UITextField(e.target).length);},[e]);
}

if (UITextField(e.target).owner.parent is NumericStepper){
NumericStepper(UITextField(e.target).owner.parent ).setStyle( "backgroundColor" , Number(fieldHighLight));
NumericStepper(UITextField(e.target).owner.parent ).setStyle("color" , Number(fieldTextHighLight));
}
}
}

public static function tFout(e:FocusEvent):void{

if (e.target is UITextField){
if (UITextField(e.target).owner is TextInput){
TextInput(UITextField(e.target).owner ).setStyle( "backgroundColor", StyleManager.getStyleDeclaration('TextInput').getStyle('backgroundColor'));
TextInput(UITextField(e.target).owner ).setStyle( "color", StyleManager.getStyleDeclaration('TextInput').getStyle('color'));
}

if (UITextField(e.target).owner is TextArea){
TextArea(UITextField(e.target).owner ).setStyle( "backgroundColor", StyleManager.getStyleDeclaration('TextInput').getStyle('backgroundColor'));
TextArea(UITextField(e.target).owner ).setStyle( "color", StyleManager.getStyleDeclaration('TextInput').getStyle('color'));
}

if (UITextField(e.target).owner.parent is ComboBox){
ComboBox(UITextField(e.target).owner.parent ).setStyle( "backgroundColor" ,  StyleManager.getStyleDeclaration('TextInput').getStyle( 'backgroundColor' ));
ComboBox(UITextField(e.target).owner.parent ).setStyle( "color" ,  StyleManager.getStyleDeclaration('TextInput').getStyle('color'));
}

if (UITextField(e.target).owner.parent is NumericStepper){
NumericStepper(UITextField(e.target).owner.parent ).setStyle( "backgroundColor", StyleManager.getStyleDeclaration('TextInput').getStyle( 'backgroundColor' ));
NumericStepper(UITextField(e.target).owner.parent ).setStyle( "color", StyleManager.getStyleDeclaration('TextInput').getStyle('color'));
}
}
}
}
}

1 Response to “How to fix stupid flash player bug with a TextField`s selection color?”


  • Hi,

    I really appreciate that after all this time (the original post was published on 07.09.2007), someone found it useful.

    Badu

Leave a Reply