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; } } }
as3.0 中对TextField的小封装,使其成为一个还不错的输入框
原创hello_world007 博主文章分类:flash ©著作权
文章标签 输入框 as3.0 TextField actionsctipt 文章分类 后端开发
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
-
有趣的CSS - 简约大方的输入框
一款简约大方的动态输入框,适用于表单提交、账号登录入口。
css 输入框 前端 ui 输入框交互 -
有趣的css - 提示文字跳起来的输入框
当输入框获取焦点准备输入时,让输入框内提示文字跳起来的交互效果。
css 动效设计 交互设计 ux/ui 输入框交互 -
android 输入框光标位置 手机输入框光标后移
qa测试手机升级以后弹框输入光标出现错位现象,前两天由于时间紧迫,一直没有找到好的解决方案,今天一天都在解决这个bug问题,临近下班终于算比较好的解决这个问题,觉得有必要理理~
android 输入框光标位置 前端 解决方案 css ios