home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / com / livebrush / ui / PropInputVertical.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  2.1 KB  |  85 lines

  1. package com.livebrush.ui
  2. {
  3.    import fl.controls.TextInput;
  4.    import flash.display.Sprite;
  5.    import flash.events.Event;
  6.    import flash.text.TextField;
  7.    import org.casalib.util.NumberUtil;
  8.    
  9.    [Embed(source="/_assets/assets.swf", symbol="symbol305")]
  10.    public class PropInputVertical extends Sprite
  11.    {
  12.       public static var upperCaseLabels:Boolean = true;
  13.       
  14.       public var max:Number = 1000;
  15.       
  16.       public var validRE:RegExp;
  17.       
  18.       public var min:Number = 0;
  19.       
  20.       public var _label:TextField;
  21.       
  22.       public var _input:TextInput;
  23.       
  24.       private var _labelStr:String = "";
  25.       
  26.       public function PropInputVertical()
  27.       {
  28.          super();
  29.          this.init();
  30.       }
  31.       
  32.       public function get enabled() : Boolean
  33.       {
  34.          return this._input.enabled;
  35.       }
  36.       
  37.       public function set value(n:Number) : void
  38.       {
  39.          this._input.text = String(n);
  40.       }
  41.       
  42.       public function set enabled(b:Boolean) : *
  43.       {
  44.          this._input.enabled = b;
  45.       }
  46.       
  47.       private function validInput(input:TextInput) : Boolean
  48.       {
  49.          return !this.validRE.test(input.text);
  50.       }
  51.       
  52.       private function init() : void
  53.       {
  54.          this.validRE = /((([\.]+(0*))$)|(([\.]+[\d]+0)$)|(-$))/;
  55.          this._input.restrict = "-.0123456789";
  56.          this._input.addEventListener(Event.CHANGE,this.changeEvent);
  57.       }
  58.       
  59.       public function get value() : Number
  60.       {
  61.          return isNaN(Number(this._input.text)) ? this.min : NumberUtil.constrain(Number(this._input.text),this.min,this.max);
  62.       }
  63.       
  64.       public function get label() : String
  65.       {
  66.          return this._label.text;
  67.       }
  68.       
  69.       public function set label(s:String) : void
  70.       {
  71.          this._labelStr = s;
  72.          this._label.text = upperCaseLabels ? s.toUpperCase() : s;
  73.       }
  74.       
  75.       public function changeEvent(e:Event) : void
  76.       {
  77.          if(e.target == this._input && !this.validInput(this._input))
  78.          {
  79.             e.stopImmediatePropagation();
  80.          }
  81.       }
  82.    }
  83. }
  84.  
  85.