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

forked from: 引数の異なる初期処理メソッドを共通的に呼び出すコード

/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/r9wF
 */

// forked from asahiufo's 引数の異なる初期処理メソッドを共通的に呼び出すコード
package {
    import flash.text.TextFieldAutoSize;
    import flash.text.TextField;
    import flash.display.Sprite;
    
    public class FlashTest extends Sprite
    // public class FlashTest extends Sprite
    {
        private var _tracer:TextField;
        
        public function show1():void { trace("show1実行"); }
        public function show2():void { trace("show2実行"); }
        
        public function FlashTest()
        {
            _tracer = new TextField();
            _tracer.autoSize = TextFieldAutoSize.LEFT;
            addChild(_tracer);
            
            var manager:Manager = new Manager();
            manager.init(
                new Base(show1),
                new Base(show2),
                new Base,
                new Square(
                    10,
                    function ():void {
                        // cusotm initializer
                        trace("area of this sqare is: " + (this.size * this.size));
                    }
                )
            );
        }
        
        private function trace(...o):void {
            _tracer.appendText(o + '\n');
        }
    }
}

class Manager
{
    public function init(...target:Array):void {
        var len:int = target.length;
        for (var i:int = 0; i < len; ++i) {
            var obj:Base = target[i];
            obj.initialize();
        }
    } 
}

class Base {
    private var _initializer:Function;
    public function Base(initiazlier:Function = null) {
        _initializer = initiazlier;
    }
    public function initialize():void {
        if (_initializer != null)
            _initializer();
    }
}

class Square extends Base {
    private var _size:Number;
    public function Square(size:Number, initializer:Function = null) {
        _size = size;
        super(initializer);
    }
    public function get size():Number { return _size; }
}