From 1be723cbd5ea6fa59a5bcc0e7670959311015201 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 2 Mar 2007 00:39:00 +0000 Subject: [PATCH] This is general purposeish and should be here. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@162 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../com/threerings/flash/ClearingTextField.as | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/as/com/threerings/flash/ClearingTextField.as diff --git a/src/as/com/threerings/flash/ClearingTextField.as b/src/as/com/threerings/flash/ClearingTextField.as new file mode 100644 index 00000000..54e9289d --- /dev/null +++ b/src/as/com/threerings/flash/ClearingTextField.as @@ -0,0 +1,56 @@ +package com.threerings.flash { + +import flash.events.TimerEvent; + +import flash.text.TextField; + +import flash.utils.Timer; + +/** + * A simple TextField with a method for setting text that will auto-clear. + */ +public class ClearingTextField extends TextField +{ + public function ClearingTextField () + { + _timer = new Timer(1, 1); + _timer.addEventListener(TimerEvent.TIMER, handleTimer); + } + + /** + * Set text that will not auto-clear. + */ + override public function set text (str :String) :void + { + setText(str, 0); + } + + /** + * Set the specified text on this TextField, and clear the text + * after the specified delay. If more text is set prior to the + * delay elapsing, the clear is pushed back to that text's delay, if any. + */ + public function setText (str :String, secondsToClear :Number = 5) :void + { + super.text = str; + _timer.reset(); // stop any running timer + + // maybe start a new countdown + if (secondsToClear > 0) { + _timer.delay = secondsToClear * 1000; + _timer.start(); + } + } + + protected function handleTimer (event :TimerEvent) :void + { + super.text = ""; + + // this should be the fragglin' default, and not updating + // should be the fragglin' exception. GAWD! + event.updateAfterEvent(); + } + + protected var _timer :Timer; +} +}