Restrict Lines

Simple decorator for text fields which allows you to restrict the number of lines available for input

Usage :

RestrictLines.decorate(myTextField,maxLines);

The class :

/**
* @author Chris Hill
*/
import ascb.util.Proxy;
 
class RestrictLines{
 
   public static function decorate(tf:TextField,maxLines:Number)
   {
       if(tf.onChanged != null)
       {
           tf["__oldOnChanged"] = tf.onChanged;
       }
       tf.onChanged = Proxy.create(RestrictLines,onChanged,maxLines);
    }
 
    public static function onChanged(tf:TextField,maxLines:Number)
    {
       //execute old function
       tf["__oldOnChanged"]();
       if(tf.bottomScroll > maxLines)
       {
           //reset to last known good size
           tf.text = tf["__oldText"];
       }
       //save the text
       tf["__oldText"] = tf.text;
   }
}

This code uses the Proxy object from the ascb library. You can read about it and download it from Person 13

Discussion

Enter your comment
 
 
restrictlines.txt · Last modified: 2005/10/05 14:51 (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki