hope i don't find dead horses here :)
(edit: ahh, I just repeat the phils link)
The Gregors singleton implementation does not protect against calling a constructor with a null value, as in:
var b:Blah = new Blah(null);
You will still only have 1 instance, but calling the constructor is still possible with the ensuing consequences.
If you absolutely must use a singleton, the constructor must make sure that the force parameter is not zero.
public function Blah( enforcer : SingletonEnforcer ) { if(!enforcer){ throw new Error("whoops!"); } }
You should also be worried about ApplicationDomain when loading swf files. External swf files that use the same definitions can have multiple singleton instances (one in each separate application domain), unless you specify that the swf file must be loaded into an existing applicationdomain.
This means that Blah.getInstance () in AAA.swf is not the same instance as Blah.getinstance () in BBB.swf if AAA.swf loads BBB.swf without an LoaderContext instance that tells the plugin to load BBB.swf in the same ApplicationDomain as AAA.swf
andkrup
source share