Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Code by rodrigolopezpeker (aka 7interactive™) on 1/29/14 12:40 PM.
- */
- package labs {
- import flash.display.Sprite;
- import flash.events.TextEvent;
- import flash.text.TextField;
- import flash.text.TextFieldType;
- import flash.text.TextFormat;
- [SWF(width="400", height="100", backgroundColor="#323232", frameRate="60")]
- public class LabMain extends Sprite {
- private var input_tf:TextField;
- private var textarea_tf:TextField;
- public function LabMain() {
- init();
- }
- private function init():void {
- input_tf = addTF(TextFieldType.INPUT, 0xffffff);
- textarea_tf = addTF(TextFieldType.DYNAMIC, 0xdedede);
- input_tf.defaultTextFormat = new TextFormat('Arial', 12, 0x565656);
- textarea_tf.defaultTextFormat = new TextFormat('Arial', 12, 0x0);
- textarea_tf.x = 200;
- input_tf.addEventListener(TextEvent.TEXT_INPUT, handleTextChange);
- stage.focus = input_tf;
- }
- private function addTF(p_type:String, p_bgColor:uint):TextField {
- var tf:TextField = new TextField();
- tf.border = true;
- tf.type = p_type;
- tf.width = 200;
- tf.borderColor = 0x0;
- tf.background = true;
- tf.multiline = true;
- tf.backgroundColor = p_bgColor;
- addChild(tf);
- return tf;
- }
- private function handleTextChange(event:TextEvent):void {
- var tf:TextField = event.currentTarget as TextField;
- if (event.text == '\n') {
- if (tf.selectedText) {
- event.preventDefault();
- sendText(tf.selectedText);
- }
- }
- }
- private function sendText(p_text:String):void {
- textarea_tf.text += p_text + '\n';
- textarea_tf.scrollV = textarea_tf.maxScrollV;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement