您的位置:首页 > 其它

鼠标选中输入文本框中某些文字后怎么变文字颜色?

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 function class