package
{
public class Singleton
{
private static var _instance:Singleton;
private static var _okToCreate:Boolean = false;
public function Singleton()
{
if( !_okToCreate ){
throw new Error("Error: " + this +
" is not a singleton and must be " +
"accessed with the getInstance() method");
}
}
public static function getInstance():Singleton
{
if( !Singleton._instance ){
_okToCreate = true;
_instance = new Singleton();
_okToCreate = false;
}
return _instance;
}
}
}