package singleton { public dynamic class Singleton { protected static var instance:Singleton; private static var flag:Boolean; public function Singleton(){ if(!flag) throw new Error("Class must be created using the getInstance method"); } public static function getInstance():Singleton{ if(!instance){ flag = true; instance = createInstance(); flag = false; } return instance; } protected static function createInstance():Singleton{ return new Singleton(); } } }