Created
May 12, 2012 07:55
-
-
Save vranystepan/2665107 to your computer and use it in GitHub Desktop.
AS3 Textbox (fixed) class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package custUI | |
{ | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.events.MouseEvent; | |
import flash.text.TextField; | |
import flash.text.TextFieldAutoSize; | |
import flash.text.TextFieldType; | |
import flash.text.TextFormat; | |
import flashx.textLayout.formats.VerticalAlign; | |
public class Textbox extends Sprite | |
{ | |
private var _fontSize:int = 40; | |
private var _width:int = Math.round(_fontSize*10); | |
private var _textFieldEntity:TextField = new TextField(); | |
private var _textFieldEntityText:String;; | |
private var _textFieldEntityStyle:TextFormat = new TextFormat(); | |
private var _textFieldBorderSprite:Sprite = new Sprite(); | |
private var _firstClicked:Boolean = false; | |
public function Textbox(value:String="") | |
{ | |
super(); | |
_textFieldEntityText = value; | |
drawEntity(); | |
} | |
private function mouseDownHandler(e:MouseEvent):void{ | |
if( ! _firstClicked ){ | |
_textFieldEntity.text = ""; | |
_firstClicked = true; | |
} | |
} | |
private function removeHandler():void{ | |
_textFieldEntity.removeEventListener(MouseEvent.CLICK, mouseDownHandler); | |
} | |
private function drawEntity():void{ | |
if(_textFieldEntityText != ""){ | |
_textFieldEntity.addEventListener(MouseEvent.CLICK, mouseDownHandler); | |
this.addEventListener(Event.REMOVED_FROM_STAGE, removeHandler); | |
} | |
_textFieldEntityStyle.color = uint("0x" + "#29121c".substr(1)); | |
_textFieldEntityStyle.size = _fontSize; | |
_textFieldEntityStyle.leftMargin = 3; | |
_textFieldEntity.border = true; | |
_textFieldEntity.borderColor = uint("0x" + "#adadaf".substr(1)); | |
_textFieldEntity.width = _width; | |
_textFieldEntity.height = _fontSize + 10; | |
_textFieldEntity.text = _textFieldEntityText; | |
_textFieldEntity.type = TextFieldType.INPUT; | |
_textFieldEntity.setTextFormat(_textFieldEntityStyle); | |
_textFieldBorderSprite.addChild(_textFieldEntity); | |
addChild(_textFieldEntity); | |
} | |
public function get text():String{ | |
return _textFieldEntity.text; | |
} | |
public function set text(value:String):void{ | |
_textFieldEntity.text = value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment