Singleton
public class Singleton
{
private static var _instanceDict :Dictionary = new Dictionary();
public static function getInstance(type : Class, autoCreation : Boolean = true) : *
{
if(!_instanceDict[type] && autoCreation)
{
_instanceDict[type] = true;
_instanceDict[type] = new type();
}
return _instanceDict[type];
}
public static function assertSingle(type : Class) : void
{
var tag : * = _instanceDict[type];
if(!tag || tag is type)
{
throw new Error("can't be instantiated whith new, please use single()");
}
}
public static function hasInstance(type : Class) : Boolean
{
return (_instanceDict[type] != null);
}
}