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

Singleton

/**
 * 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;
    }
    
}