Right now what i have done is i appended a space at the end of text and using setTextFormat i set its color. then it works like i want. BUT still there are 2 problems
- space is always included which user has to MANUALLY REMOVE
- i can't added character inbetween i can only append at the end of text
If i remove space character then format is reset to original only..... so can't even remove that character programmatically.
Just to let u know..
Thanks alot
Regards
:
import fl.controls.Button;
import fl.controls.TextArea;
import flash.text.TextField;
import flash.events.MouseEvent;
var tf2:TextField = createTextField(100,100,200,22,true);
tf2.type = 'input';
tf2.background = true;
tf2.backgroundColor = 0x777777;
tf2.width = 400;
tf2.height = 200;
tf2.x = 100;
tf2.y = 100;
var df1:TextFormat = new TextFormat();
df1.bold = false;
//df1.align = "center";
df1.color = 0xffffff;
df1.size = 14;
tf2.defaultTextFormat = df1;
tf2.text = "[text]";
//tf2.setTextFormat(df1, 0);
//addChild(ta2);
//ta2.move(150,100);
tf2.addEventListener(Event.CHANGE,f);
function f(e:Event):void{
tf2.setTextFormat(df1,tf2.caretIndex-1);
}
var btn_Colour_Red:Button = new Button();
btn_Colour_Red.label = "Red";
btn_Colour_Red.addEventListener(MouseEvent.CLICK, btn_Colour_Red_Clicked);
btn_Colour_Red.setSize(40, 20);
btn_Colour_Red.move(350, 0);
addChild(btn_Colour_Red);
var btn_Colour_Blue:Button = new Button();
btn_Colour_Blue.label = "Blue";
btn_Colour_Blue.addEventListener(MouseEvent.CLICK, btn_Colour_Blue_Clicked);
btn_Colour_Blue.setSize(40, 20);
btn_Colour_Blue.move(250, 0);
addChild(btn_Colour_Blue);
function btn_Colour_Red_Clicked(e:MouseEvent) {
df1.bold = false;
df1.align = "center";
df1.color = 0xFF0000;
df1.size = 14;
//ta2.setFocus();
stage.focus = tf2;
}
function btn_Colour_Blue_Clicked(e:MouseEvent) {
df1.bold = false;
df1.align = "center";
df1.color = 0x0000FF;
df1.size = 14;
//ta2.setFocus();
stage.focus = tf2
}
function createTextField(x:Number, y:Number, width:Number, height:Number, border:Boolean):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
result.background = true;
result.border = border;
addChild(result);
return result;
}