Singleton

by kamipoo
♥4 | Line 25 | Modified 2009-07-27 17:45:40 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            var singleton:Singleton = Singleton.getInstance();
        }
    }
}

class Singleton {
    
    private static var _INTERNAL_CALL:Boolean = false;
    private static var _INSTANCE:Singleton;
    
    public function Singleton() {
        if(!_INTERNAL_CALL) {
            new ArgumentError("error");
        }
    }
    
    public static function getInstance():Singleton {
        if(!_INSTANCE) {
            _INTERNAL_CALL = true;
            _INSTANCE = new Singleton();
            _INTERNAL_CALL = false;
        }
        return _INSTANCE;
    }
    
}

Forked