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

MinimalComps test

MinimalCompsのテスト
並べるだけじゃ味気ないので、ミニゲームにしてみた。
Get Adobe Flash player
by Fake 16 Nov 2010
/**
 * Copyright Fake ( http://wonderfl.net/user/Fake )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/lGWI
 */

package {
    import flash.events.MouseEvent;
    import flash.display.Sprite;
    import com.bit101.components.Text;
    public class FlashTest extends Sprite {
        private var uFieldSize:uint = 3;
        private var arField:Array;
        private var debugout:Text;

        public function FlashTest() {
            // init button array
            arField = new Array();
            for (var y:int = 0; y < uFieldSize; ++y) {
                arField[y] = new Array();
                for (var x:int = 0; x < uFieldSize; ++x) {
                    var btn:DynamicPushButton = new DynamicPushButton(this, x * 40, y * 40, "o", onButtonClick);
                    btn.name = "btn" + y.toString() + x.toString();
                    btn.data = {
                        x: x, y: y
                    }
                    btn.setSize(32, 32);
                    btn.toggle = true;
                    arField[y][x] = {
                        button: btn,
                        state: true
                    };
                }
            }
            // shuffle
            for (var i:int = 0; i < 10; ++i) {
                x = Math.floor(Math.random() * uFieldSize);
                y = Math.floor(Math.random() * uFieldSize);
                arField[y][x].button.doToggle();
                procToggle(x, y);
            }
            debugout = new Text(this, 200, 50, "Set all button to 'o'.\n");
            debugout.editable = false;
        }
        
        private function onButtonClick(e:MouseEvent):void {
            var btn:DynamicPushButton = (DynamicPushButton)(e.target);
            if (btn.selected) {
                btn.label = "x";
            } else {
                btn.label = "o";
            }
            procToggle(btn.data.x, btn.data.y);
            for (var y:int = 0; y < uFieldSize; ++y) {
                for (var x:int = 0; x < uFieldSize; ++x) {
                    if (arField[y][x].button.selected) {
                        return;
                    }
                }
            }
            debugout.textField.appendText("OK\n");
        }
        
        private function procToggle(x:uint, y:uint):void {
            if (0 < x) {
                arField[y][x-1].button.doToggle();
            }
            if (x < uFieldSize - 1) {
                arField[y][x+1].button.doToggle();
            }
            if (0 < y) {
                arField[y-1][x].button.doToggle();
            }
            if (y < uFieldSize - 1) {
                arField[y+1][x].button.doToggle();
            }
        }
    }
}

import com.bit101.components.PushButton;
import flash.display.DisplayObjectContainer;
dynamic class DynamicPushButton extends PushButton {
    public function DynamicPushButton(parent:DisplayObjectContainer = null, xpos:Number = 0, ypos:Number = 0, label:String = "", defaultHandler:Function = null) {
        super(parent, xpos, ypos, label, defaultHandler);
    }

    public function doToggle():void {
        selected = !selected;
        label = selected ? "x" : "o";
    }
}