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 / ThresholdInputs.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  3.9 KB  |  148 lines

  1. package com.livebrush.ui
  2. {
  3.    import fl.controls.CheckBox;
  4.    import fl.controls.TextInput;
  5.    import flash.display.Sprite;
  6.    import flash.events.Event;
  7.    import org.casalib.util.NumberUtil;
  8.    
  9.    [Embed(source="/_assets/assets.swf", symbol="symbol384")]
  10.    public class ThresholdInputs extends Sprite
  11.    {
  12.       public var _min:TextInput;
  13.       
  14.       public var minIn:Number = 0;
  15.       
  16.       public var _max:TextInput;
  17.       
  18.       public var maxIn:Number = 1000;
  19.       
  20.       public var _active:CheckBox;
  21.       
  22.       public var validRE:RegExp;
  23.       
  24.       public function ThresholdInputs()
  25.       {
  26.          super();
  27.          this.init();
  28.          this.__setProp__active_ThresholdInputs_Layer1_0();
  29.       }
  30.       
  31.       public function get enabled() : Boolean
  32.       {
  33.          return this._active.enabled;
  34.       }
  35.       
  36.       public function set enabled(b:Boolean) : void
  37.       {
  38.          this._max.enabled = this._min.enabled = this._active.enabled = b;
  39.       }
  40.       
  41.       public function get active() : Boolean
  42.       {
  43.          return this._active.selected;
  44.       }
  45.       
  46.       public function set max(n:Number) : void
  47.       {
  48.          this._max.text = String(n);
  49.       }
  50.       
  51.       private function _setActive(b:Boolean) : void
  52.       {
  53.          this._active.selected = b;
  54.          this._max.enabled = this._min.enabled = this._active.selected;
  55.       }
  56.       
  57.       public function set active(b:Boolean) : void
  58.       {
  59.          this._setActive(b);
  60.       }
  61.       
  62.       private function init() : void
  63.       {
  64.          this.validRE = /((([\.]+(0*))$)|(([\.]+[\d]+0)$)|(-$))/;
  65.          this.active = false;
  66.          this._min.restrict = this._max.restrict = "-.0123456789";
  67.          addEventListener(Event.CHANGE,this.activeChange);
  68.       }
  69.       
  70.       private function activeChange(e:Event) : void
  71.       {
  72.          if(e.target == this._active)
  73.          {
  74.             this._setActive(this._active.selected);
  75.          }
  76.          else if(e.target == this._min && !this.validInput(this._min))
  77.          {
  78.             e.stopImmediatePropagation();
  79.          }
  80.          else if(e.target == this._max && !this.validInput(this._max))
  81.          {
  82.             e.stopImmediatePropagation();
  83.          }
  84.       }
  85.       
  86.       public function get min() : Number
  87.       {
  88.          return isNaN(Number(this._min.text)) ? this.minIn : NumberUtil.constrain(Number(this._min.text),this.minIn,this.maxIn);
  89.       }
  90.       
  91.       private function toggleInputs(s:Boolean) : void
  92.       {
  93.          var input:TextInput = s ? this._min : this._max;
  94.          input.visible = !input.visible;
  95.          input.enabled = input.visible;
  96.       }
  97.       
  98.       public function toggleMin() : void
  99.       {
  100.          this.toggleInputs(true);
  101.       }
  102.       
  103.       public function set min(n:Number) : void
  104.       {
  105.          this._min.text = String(n);
  106.       }
  107.       
  108.       public function get max() : Number
  109.       {
  110.          return isNaN(Number(this._max.text)) ? this.minIn : NumberUtil.constrain(Number(this._max.text),this.minIn,this.maxIn);
  111.       }
  112.       
  113.       public function toggleMax() : void
  114.       {
  115.          this.toggleInputs(false);
  116.       }
  117.       
  118.       private function validInput(input:TextInput) : Boolean
  119.       {
  120.          return !this.validRE.test(input.text);
  121.       }
  122.       
  123.       internal function __setProp__active_ThresholdInputs_Layer1_0() : *
  124.       {
  125.          try
  126.          {
  127.             this._active["componentInspectorSetting"] = true;
  128.          }
  129.          catch(e:Error)
  130.          {
  131.          }
  132.          this._active.enabled = true;
  133.          this._active.label = "";
  134.          this._active.labelPlacement = "right";
  135.          this._active.selected = false;
  136.          this._active.visible = true;
  137.          try
  138.          {
  139.             this._active["componentInspectorSetting"] = false;
  140.          }
  141.          catch(e:Error)
  142.          {
  143.          }
  144.       }
  145.    }
  146. }
  147.  
  148.