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

パラメーターのコントロール用

...
@author gk
Get Adobe Flash player
by kappaLab 15 Jul 2009
/**
 * Copyright kappaLab ( http://wonderfl.net/user/kappaLab )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/yQU7
 */

package  
{
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.Dictionary;
    
    /**
     * ...
     * @author gk
     */
    public class ParamController extends Sprite
    {
        
        private var s:Shape
        private var phaseX:Number;
        private var phaseY:Number;
        private var vX:Number;
        public var vY:Number;
        private var c:Controller;
        public function ParamController() 
        {
            vX = .1;
            vY = .1;
            phaseX = 0;
            phaseY = 0;
            s = addChild(new Shape()) as Shape;
            s.graphics.beginFill(0x000000);
            s.graphics.drawCircle(0,0, 10);
            addEventListener(Event.ENTER_FRAME, onEnter)
            
            Controller.initialize(stage)
            c = new Controller(vX,"vX",.005);
            new Controller().addTarget(this, "vY",.005);
            
        }
        
        private function onEnter(e:Event):void 
        {
            phaseX += c.value;
            phaseY += vY;
            s.x = Math.sin(phaseX) * 200 + 250;
            s.y = Math.cos(phaseY) * 200 + 250;
        }
        
    }
    
}

import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.Sprite
import flash.display.Stage;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.ui.Keyboard
class Controller extends Sprite
{
    private static var list:Array = []
    private static var _stage:Stage;
    
    private var valueField:TextField;
    private var nameField:TextField;
    private var background:Shape;
    public var value:Number;
    public var step:Number;
    public var propatyName:String;
    private var target:*;
    private var interval:int
    
    function Controller(value:Number=1.0,propatyName:String = "param",step:Number = 1.0)
    {
        this.value = value;
        this.step = step;
        this.propatyName = propatyName;
        interval = 0
        init()
    }
    static public function initialize(stage:Stage):void
    {
        _stage = stage
    }
    
    public function addTarget(target:*,propatyName:String,step:Number = 1.0):void
    {
        this.target = target;
        this.propatyName = propatyName;
        this.step = step;
        value = target[propatyName];
        
        nameField.text = propatyName + " : ";
        
        valueField.x = nameField.width; 
        valueField.text = value.toString();
        

    }
    
    private function init():void
    {
        Controller.list.push(this)
        
        nameField = addChild(new TextField()) as TextField;
        nameField.selectable = false;
        nameField.autoSize = TextFieldAutoSize.LEFT;
        nameField.defaultTextFormat = new TextFormat("Verdana",9);
        nameField.text = propatyName + " : ";
        
        valueField = addChild(new TextField()) as TextField;
        valueField.x = nameField.width; 
        valueField.type = TextFieldType.INPUT;
        valueField.autoSize = TextFieldAutoSize.LEFT;
        valueField.defaultTextFormat = new TextFormat("Verdana",9);
        valueField.text = value.toString();
        valueField.tabIndex = list.length

        background = addChildAt(new Shape(),0) as Shape;
        background.graphics.beginFill(0x999999);
        background.graphics.drawRect(0, 0, 60, height);
        background.alpha = .5;
        
        this.y = list.length * (height + 5);
        
        addEventListener(Event.ADDED_TO_STAGE, onAdded);
        addEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
        _stage.addChild(this);
    }
    
    private function onRemoved(e:Event):void 
    {
        removeEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
        valueField.removeEventListener(KeyboardEvent.KEY_UP, onKeyup);
        valueField.removeEventListener(KeyboardEvent.KEY_DOWN, onKeydown);
        valueField.removeEventListener(FocusEvent.FOCUS_IN,onFocusIn);
        valueField.removeEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
        removeEventListener(MouseEvent.MOUSE_DOWN, onMousedown);
        removeEventListener(MouseEvent.MOUSE_UP, onMouseup);
        removeEventListener(Event.ENTER_FRAME,onIncrement)
        removeEventListener(Event.ENTER_FRAME,onDecrement)

    }
    
    private function onAdded(e:Event):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, onAdded);
        valueField.addEventListener(KeyboardEvent.KEY_UP, onKeyup);
        valueField.addEventListener(KeyboardEvent.KEY_DOWN, onKeydown);
        valueField.addEventListener(FocusEvent.FOCUS_IN,onFocusIn);
        valueField.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
        addEventListener(MouseEvent.MOUSE_DOWN, onMousedown);
        addEventListener(MouseEvent.MOUSE_UP, onMouseup);
    }
    
    private function onKeydown(e:KeyboardEvent):void 
    {
        switch(e.keyCode)
        {
            case Keyboard.UP:
             addEventListener(Event.ENTER_FRAME, onIncrement)
            break; 
            case Keyboard.DOWN:
             addEventListener(Event.ENTER_FRAME, onDecrement)
            break;
        }
        
    }
    
    private function onDecrement(e:Event):void 
    {
        if (interval-- > 0) return;
        interval = 4 
        value -= step;
        valueField.text = value.toString();
        if (target) target[propatyName] = value;
    }
    
    private function onIncrement(e:Event):void 
    {
        if (interval-- > 0) return;
        interval = 4 
        value += step;
        valueField.text = value.toString();
        if (target) target[propatyName] = value;        
    }
    
    
    private function onMouseup(e:MouseEvent):void 
    {
        stopDrag();
    }
    
    private function onMousedown(e:MouseEvent):void 
    {
        startDrag();
        removeEventListener(Event.ENTER_FRAME,onIncrement)
        removeEventListener(Event.ENTER_FRAME,onDecrement)
    }
    
    private function onFocusOut(e:FocusEvent):void 
    {
        background.alpha = .5;
        removeEventListener(Event.ENTER_FRAME,onIncrement)
        removeEventListener(Event.ENTER_FRAME,onDecrement)
    }
    
    private function onFocusIn(e:FocusEvent):void 
    {
        background.alpha = 1;
    }
        
    private function onKeyup(e:KeyboardEvent):void 
    {
        removeEventListener(Event.ENTER_FRAME,onIncrement)
        removeEventListener(Event.ENTER_FRAME,onDecrement)

        switch(e.keyCode)
        {
            case Keyboard.UP:
             value += step
             valueField.text = value.toString();
             if (target) target[propatyName] = value;
            break;
            case Keyboard.DOWN:
             value -= step;
             valueField.text = value.toString();
             if (target) target[propatyName] = value;
            break;
            case Keyboard.ENTER:
             if (Number(valueField.text)) value = Number(valueField.text)
             else valueField.text = value.toString(); 
             if (target) target[propatyName] = value;
            break;

        }
    }
}