鼠标选中输入文本框中某些文字后怎么变文字颜色?
2009-09-07 22:13
656 查看
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
import flash.text.TextFieldType;
public class TextField_setTextFormatExample extends Sprite {
private var myTextField:TextField = new TextField();
private var newFormat:TextFormat = new TextFormat();
public function TextField_setTextFormatExample() {
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.selectable = true;
myTextField.background = true;
myTextField.type = TextFieldType.INPUT;
myTextField.text = "No matter where you click on this text field only the TEXT IN ALL CAPS changes format.";
myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
newFormat.color = 0xFF0000;
newFormat.size = 18;
newFormat.underline = true;
newFormat.italic = true;
this.addChild(myTextField);
}
private function clickHandler(event:MouseEvent):void {
var tf:TextField = TextField(event.target);
var currentTextFormat:TextFormat = myTextField.getTextFormat(55);
if(currentTextFormat.size != 18) {
myTextField.setTextFormat(newFormat,tf.selectionBeginIndex, tf.selectionEndIndex);
}
else {
myTextField.setTextFormat(myTextField.defaultTextFormat);
}
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
import flash.text.TextFieldType;
public class TextField_setTextFormatExample extends Sprite {
private var myTextField:TextField = new TextField();
private var newFormat:TextFormat = new TextFormat();
public function TextField_setTextFormatExample() {
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.selectable = true;
myTextField.background = true;
myTextField.type = TextFieldType.INPUT;
myTextField.text = "No matter where you click on this text field only the TEXT IN ALL CAPS changes format.";
myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
newFormat.color = 0xFF0000;
newFormat.size = 18;
newFormat.underline = true;
newFormat.italic = true;
this.addChild(myTextField);
}
private function clickHandler(event:MouseEvent):void {
var tf:TextField = TextField(event.target);
var currentTextFormat:TextFormat = myTextField.getTextFormat(55);
if(currentTextFormat.size != 18) {
myTextField.setTextFormat(newFormat,tf.selectionBeginIndex, tf.selectionEndIndex);
}
else {
myTextField.setTextFormat(myTextField.defaultTextFormat);
}
}
}
}
相关文章推荐
- HTML中输入无限文字的文本框,可以随鼠标拖动大小
- CSS文字被鼠标选中后的文字颜色及背景
- ubuntu 修改鼠标左键选中文字的颜色
- ubuntu 修改鼠标左键选中文字的颜色
- (vb6小技巧)鼠标在文本框一按下就选中所有文字
- IE浏览器控件页面如何在选中的文本框输入焦点输入文字
- CSS改变被鼠标选中的文字颜色及背景
- h5页面中虚化文本框默认内容,当输入文字后默认内容消失怎么做?
- CSS改变网页中鼠标选中文字背景颜色例子
- 怎么利用runtime来改变文本框占位文字的颜色?
- ubuntu 修改鼠标左键选中文字的颜色
- IE网页文本框中无法输入文字解决方法
- html中点击radio后的文字相当于选中该单选按钮如何实现?怎么实现两个redio,选中一个,取消另一个?
- css如何让文本框中的输入的文字始终垂直居中
- html中input文本框,初始里边有文字提示,当点击输入文字时,原文字消失
- UITabBarController设置选中时图片和文字的颜色
- iOS 输入文字时文本框上移
- 改变listview中item选中时文字的颜色
- 为页面上某些文本框添加离开验证输入事件
- 禁止鼠标选中文字