In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Controllable

generic container with controls
Get Adobe Flash player
by aobyrne 01 Apr 2011
/**
 * Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dAsY
 */

package {
    import com.bit101.components.HSlider;
    import com.bit101.components.Label;
    import com.bit101.components.NumericStepper;
    import com.bit101.components.PushButton;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.ColorTransform;
    public class Controllable extends Sprite {
         private var n : Number = 0;
        private var label:Label;
        private var hSlider:HSlider;
        private var _isPlaying:Boolean;
        private var pushButton:PushButton;
        private var step:NumericStepper;
        private var degrees:Label;
        private const MAXIMUM:Number = 100;
        private const MINIMUM:Number = 0;
        private const STEP:Number = 1;
        private const PRECISION:Number = 0;
        public function Controllable() {
            label = new Label(this, 0, 0, "");
            pushButton = new PushButton(this, 40, 0, '', play);
            step = new NumericStepper(this, 145, 0, nsDraw);
            step.minimum = 0;
            step.maximum = MAXIMUM;
            step.step = STEP;
            step.labelPrecision = PRECISION;
            
            hSlider = new HSlider(this, 0, stage.stageHeight - 20, slideDraw);
            hSlider.setSize(stage.stageWidth - 2, hSlider.height);
            hSlider.minimum = 0;
            hSlider.maximum = MAXIMUM;
            /*/
            play();
            /*/
            update(null);
            isPlaying = false;
            //*/
        }
        
        private function nsDraw(e:Event):void 
        {
            n = NumericStepper(e.target).value;
            update(null);
        }
        
        private function slideDraw(e:Event):void 
        {
            n = HSlider(e.target).value;
            update(null);
        }
        
        private function play(e:Event):void 
        {
            if (_isPlaying) 
            {
                stage.removeEventListener(Event.ENTER_FRAME, update);
            }
            else
            {
                stage.addEventListener(Event.ENTER_FRAME, update);
            }
            isPlaying = !_isPlaying;

        }

        private function update(event : Event) : void
        {
            label.text =  n.toFixed(PRECISION);
            hSlider.value = n;
            step.value = n;
            if (event) 
            {
                n += STEP;
            }
                if (n>=MAXIMUM) 
                {
                    n = MINIMUM;
                }
        }
        
        public function set isPlaying(value:Boolean):void 
        {
            pushButton.label = value?"stop":"play";
            pushButton.transform.colorTransform =value? new ColorTransform(1, 0, 0, 1):new ColorTransform(0, 1, 0, 1);
            _isPlaying = value;
        }
            
        }
    }