home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.ui
- {
- import fl.controls.TextInput;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.text.TextField;
- import org.casalib.util.NumberUtil;
-
- [Embed(source="/_assets/assets.swf", symbol="symbol305")]
- public class PropInputVertical extends Sprite
- {
- public static var upperCaseLabels:Boolean = true;
-
- public var max:Number = 1000;
-
- public var validRE:RegExp;
-
- public var min:Number = 0;
-
- public var _label:TextField;
-
- public var _input:TextInput;
-
- private var _labelStr:String = "";
-
- public function PropInputVertical()
- {
- super();
- this.init();
- }
-
- public function get enabled() : Boolean
- {
- return this._input.enabled;
- }
-
- public function set value(n:Number) : void
- {
- this._input.text = String(n);
- }
-
- public function set enabled(b:Boolean) : *
- {
- this._input.enabled = b;
- }
-
- private function validInput(input:TextInput) : Boolean
- {
- return !this.validRE.test(input.text);
- }
-
- private function init() : void
- {
- this.validRE = /((([\.]+(0*))$)|(([\.]+[\d]+0)$)|(-$))/;
- this._input.restrict = "-.0123456789";
- this._input.addEventListener(Event.CHANGE,this.changeEvent);
- }
-
- public function get value() : Number
- {
- return isNaN(Number(this._input.text)) ? this.min : NumberUtil.constrain(Number(this._input.text),this.min,this.max);
- }
-
- public function get label() : String
- {
- return this._label.text;
- }
-
- public function set label(s:String) : void
- {
- this._labelStr = s;
- this._label.text = upperCaseLabels ? s.toUpperCase() : s;
- }
-
- public function changeEvent(e:Event) : void
- {
- if(e.target == this._input && !this.validInput(this._input))
- {
- e.stopImmediatePropagation();
- }
- }
- }
- }
-
-