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

color2

丸をドラッグして枠内に放り込むと色が変わる。それだけ。
Get Adobe Flash player
by Scmiz 12 Apr 2011
    Embed
/**
 * Copyright Scmiz ( http://wonderfl.net/user/Scmiz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cg2N
 */

package {
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            stage.frameRate = 60;
            
            var pool:Pool = new Pool();
            this.addChild(pool);
            
            var sphereArray:Array = new Array();
            var onDown:Function = function(id:uint):Function {
                return function(e:MouseEvent):void {
                    sphereArray[id].startDrag();
                };
            };            
            var onUp:Function = function(id:uint):Function {
                return function(e:MouseEvent):void {
                    sphereArray[id].stopDrag();
                    if (pool.hitTestObject(sphereArray[id])) {
                        sphereArray[id].visible = false;
                        pool.add(sphereArray[id].color);
                    }

                };
            };            

            for (var index:uint = 0; index < 45; ++index) {
                var x:Number = 95 + ((index % 15) * 20);
                var y:Number = 340 + (uint(index / 15) * 20);
                var sphere:ColorSphere = new ColorSphere(x, y, index % ColorSphere.Color_Num);
                sphere.addEventListener(MouseEvent.MOUSE_DOWN, onDown(index));
                sphere.addEventListener(MouseEvent.MOUSE_UP, onUp(index));
                sphereArray.push(sphere);
                this.addChild(sphere);
            }
            
            var proc:Function = function(e:Event):void {
                pool.update();
            };
            this.addEventListener(Event.ENTER_FRAME, proc);
        }
    }
}
import flash.display.SimpleButton;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Sprite;

class Pool extends Sprite {
    private var _sphereArray:Array;
    private var _r:uint;
    private var _g:uint;
    private var _b:uint;
    private var _rTarget:uint;
    private var _gTarget:uint;
    private var _bTarget:uint;

    public function Pool() {
        _sphereArray = new Array();
        for (var index:uint = 0; index < ColorSphere.Color_Num; ++index) {
            _sphereArray.push(0);
        }
        _r = 255;
        _g = 255;
        _b = 255;
        _rTarget = 255;
        _gTarget = 255;
        _bTarget = 255;
    }

    public function add(color:uint):void {
        ++_sphereArray[color];
        
        var all:uint = 0;
        for (var index:uint = 0; index < ColorSphere.Color_Num; ++index) {
            all += _sphereArray[index];
        }

        var step:uint = 10;        
        _rTarget = 255 - (all * step) + (_sphereArray[ColorSphere.Color_Red] * step);
        _gTarget = 255 - (all * step) + (_sphereArray[ColorSphere.Color_Green] * step);
        _bTarget = 255 - (all * step) + (_sphereArray[ColorSphere.Color_Blue] * step);
    }
    
    public function update():void {
        var centerX:Number = 232.5;
        var centerY:Number = 232.5 - 50.0;

        var sizeL:Number = 240;
        var sizeS:Number = 220;
        var round:Number = 12;
        
        var intpRate:Number = 0.01;
        _r = (_r * (1.0 - intpRate)) + (_rTarget * intpRate);
        _g = (_g * (1.0 - intpRate)) + (_gTarget * intpRate);
        _b = (_b * (1.0 - intpRate)) + (_bTarget * intpRate);
        
        this.graphics.clear();
        this.graphics.beginFill(0x808080);
        this.graphics.drawRoundRect(centerX - (sizeL / 2), centerY - (sizeL / 2), sizeL, sizeL, round);
        this.graphics.endFill();
        this.graphics.beginFill((_r << 16) + (_g << 8) + (_b << 0));
        this.graphics.drawRoundRect(centerX - (sizeS / 2), centerY - (sizeS / 2), sizeS, sizeS, round);
        this.graphics.endFill();
    }
}

class ColorSphere extends Sprite {
    static public const Color_Red:uint = 0;
    static public const Color_Green:uint = 1;
    static public const Color_Blue:uint = 2;
    static public const Color_Num:uint = 3;
    
    private var _color:uint;
    
    public function ColorSphere(x:Number, y:Number, color:uint) {
        this.x = x;
        this.y = y;
        _color = color;
        
        var fillColor:uint = 0;
        switch (_color) {
            case Color_Red:   fillColor = 0xff4040; break;
            case Color_Green: fillColor = 0x40d040; break;
            case Color_Blue:  fillColor = 0x4040ff; break;
        }

        var radius:Number = 4;
        this.graphics.beginFill(fillColor);
        this.graphics.drawCircle(-radius, -radius, radius * 2);
        this.graphics.endFill();
    }
    
    public function get color():uint {
        return _color;
    }

}