// // $Id$ package com.threerings.flex { import flash.events.FocusEvent; import mx.controls.TextInput; /** * A special TextInput for entering Chat. One of these is used in ChatControl. * * A standard TextInput has the stupid behavior of selecting all the text when it receives * focus. Disable that so that we can receive focus and people can type and we don't blow away * whatever they had before. */ public class ChatInput extends TextInput { public function ChatInput () { styleName = "chatInput"; width = 147; showPrompt(true); } protected function showPrompt (show :Boolean) :void { setStyle("backgroundImage", (show && ("" == text)) ? PROMPT : undefined); } override protected function focusInHandler (event :FocusEvent) :void { var oldValue :Boolean = textField.selectable; textField.selectable = false; try { super.focusInHandler(event); } finally { textField.selectable = oldValue; } showPrompt(false); } override protected function focusOutHandler (event :FocusEvent) :void { super.focusOutHandler(event); showPrompt(true); } [Embed(source="typetochat.png")] protected static const PROMPT :Class; } }