Skip to main content
This topic has been closed for replies.

1 reply

Sat_Du_Loiret
Participant
August 13, 2014

I modified the SliderUI of  Matt Przybylski [reintroducing.com] and renamed SliderUIS   

      in class added private var center:Number, _align:Number

 

    public function SliderUIS(Contain:Sprite,axis:String,track:Sprite,slider:Sprite,lowValue:Number,hightValue:Number,startValue:Number =0,precision:int =0,TrackAlignDegre:Number = 0:void

added arg:TrackAlignDegre for start angle, axis "c" for circular type.       

          switch( this._axis) {           

              case "x":    this._changeProperty = "width"; break;           

              case "y":    this._changeProperty = "height"; break;

added      case "c":    this._align = Math.round(TrackAlignDegre); this._changeProperty = "rotation"; center = Contain.width / 2; break }// center is middle of container.


in function manageRestingPosition:       

          switch ( this._axis){           

              case "x": this._slider[this._axis] = (this._track[this._axis] + (this._percent * this._track[this._changeProperty])); break;           

              case "y": this._slider[this._axis] = (this._track[this._axis] - (this._percent * this._track[this._changeProperty])); break;

added      case "c": this._slider[this._changeProperty] =  value - this._align + 90; //Output.clear();


in function handleMouseDown:       

          switch (this._axis){           

              case "x": this._slider.startDrag(false, new Rectangle(this._track.x, this._slider.y, this._track.width, 0)); break;           

              case "y": this._slider.startDrag(false, new Rectangle(this._slider.x, this._track.y, 0, -this._track.height)); break;           

added      case "c": this._track.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove, false, 0, true); break; }


//added. only for axis = "c"       

          private function handleMouseMove(evt:MouseEvent):void {       

              if (evt.target.name == this._track.name){           

                  this._currentValue =  Math.floor((Math.atan2(( this._contain.mouseX - center), - ( this._contain.mouseY - center)) * constant.AM) + this._align - 90);           

                  //Output.clear(); Output.trace( "in SUIS MouseMove  align: " + this._align + Current.value: " + this._currentValue); //Output.trace senocular           

                  if ( this._currentValue < 0) this._currentValue += 360; this.manageRestingPosition(this._currentValue);           

                  this.dispatchEvent(new SliderUIEvent( constant.SUI_UPDATE, this._percent, this._currentValue, this._slider, this._track,true));}}


in function handleMouseUp:   

          if ( this._axis == "c") { this._track.removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove)} else this._slider.stopDrag() ;

          this.dispatchEvent(new SliderUIEvent( constant.SUI_RELEASE, this._percent, this._currentValue, this._slider, this._track)); this._timer.reset();

          this._stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp); }


in function updateInfo: switch (this._axis) {             

            case "x": case "y": this._percent = Math.abs((this._slider[this._axis] - this._track[this._axis]) / this._track[this._changeProperty]); this._currentValue = this.roundToPrecision((this._lowValue + (this._range * this._percent)), this._precision); break;

added    case "c": this._percent = ( this._slider.rotation / this._range); break; } Good luck !

[link deactivated by moderator]

Participating Frequently
August 20, 2014

thanks