package myComponent { import flash.display.Shape; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldType; import flash.text.TextFormat; import flash.text.TextLineMetrics; public class MyInput extends Sprite { private var _myTextField:TextField = new TextField();//文本框的文本域 private var mySprite:Sprite = new Sprite(); private var _defaultValue:String = ‘hello‘;//默认值 private var _backGroudColor:uint = 0xffffff;//文本框背景颜色 默认为白色 private var _paddingWidth:uint = 120; //TextField的默认长度 private var _asPassworldDisplay:Boolean = false;//是否作为密码框来显示 private var _borderColor:uint = 0xD4D4D4;//输入边框颜色 private var _bordersize:uint = 1;//输入边框大小 private var _paddingHorizontalVal:uint = 1;//输入边框内TextField与边框的左右距离 private var _paddingVerticalVal:uint = 2;//输入边框内TextField与边框的上下距离 private var _borderRadius:uint = 2;//输入边框四个角的圆角半径 private var _textFontSize:uint = 16; //设置TextField中的字体大小 private var _textFontColor:uint = 0x000000;//设置TextField中字体颜色 private var _textFontFamily:String = ‘‘;//设置TextField中的字体 public function MyInput() { } private function initTextField():void { this.myTextField.type = TextFieldType.INPUT;//设置TextField是可输入的 this.myTextField.text = this._defaultValue;//设置TextField的默认输入 //设置TextField中的字体 var myFormat:TextFormat = new TextFormat(); myFormat.size = this._textFontSize; myFormat.color = this._textFontColor; if (!this._textFontFamily) { myFormat.font = this._textFontFamily; } this._myTextField.setTextFormat(myFormat); //设置TextField的背景颜色 this.myTextField.background = true; this.myTextField.backgroundColor = this._backGroudColor; //设置TextField的长宽 this.myTextField.width = this._paddingWidth ; var textLineInfo:TextLineMetrics = this.myTextField.getLineMetrics(0); this.myTextField.height = textLineInfo.ascent +textLineInfo.descent + 4; //是否作为密码框来显示 this.myTextField.displayAsPassword = this._asPassworldDisplay; //描绘边框 var borderShape:Shape = new Shape(); borderShape.graphics.lineStyle(this._bordersize, this._borderColor); borderShape.graphics.drawRoundRect(0, 0, this._paddingWidth+this._paddingHorizontalVal*2, this.myTextField.height +this._paddingVerticalVal*2, this._borderRadius, this._borderRadius); this.addChild(borderShape); //设置TextField的位置 this.myTextField.x = this._paddingHorizontalVal; this.myTextField.y = this._paddingVerticalVal; this.addChild(this._myTextField); } public function initDraw():void { this.initTextField(); } public function get defaultValue():String { return _defaultValue; } public function set defaultValue(value:String):void { _defaultValue = value; } public function get backGroudColor():uint { return _backGroudColor; } public function set backGroudColor(value:uint):void { _backGroudColor = value; } public function get paddingWidth():uint { return _paddingWidth; } public function set paddingWidth(value:uint):void { _paddingWidth = value; } public function get asPassworldDisplay():Boolean { return _asPassworldDisplay; } public function set asPassworldDisplay(value:Boolean):void { _asPassworldDisplay = value; } public function get borderColor():uint { return _borderColor; } public function set borderColor(value:uint):void { _borderColor = value; } public function get bordersize():uint { return _bordersize; } public function set bordersize(value:uint):void { _bordersize = value; } public function get paddingHorizontalVal():uint { return _paddingHorizontalVal; } public function set paddingHorizontalVal(value:uint):void { _paddingHorizontalVal = value; } public function get paddingVerticalVal():uint { return _paddingVerticalVal; } public function set paddingVerticalVal(value:uint):void { _paddingVerticalVal = value; } public function get myTextField():TextField { return _myTextField; } public function set myTextField(value:TextField):void { _myTextField = value; } public function get textFontSize():uint { return _textFontSize; } public function set textFontSize(value:uint):void { _textFontSize = value; } public function get textFontColor():uint { return _textFontColor; } public function set textFontColor(value:uint):void { _textFontColor = value; } public function get textFontFamily():String { return _textFontFamily; } public function set textFontFamily(value:String):void { _textFontFamily = value; } } }
时间: 2024-11-08 23:45:49