“What? The singleton pattern is gone in FDT3 actionscript 3?” No it’s not! You just have to alter a bit of code to get it to work. FDT didn’t include this template in their version 3. I got the pattern from “Actionscript 3 with Design Patterns“. Here’s the template code to have the CTRL-space-singleton action back again
Open FDT preferences, goto templates, then add a new one for AS3 and copy paste the code below (click continue reading)
package ${enclosing_package}
{
/**
* @author ${user}
*/
public class ${enclosing_type}
{
private static var __instance:${enclosing_type};
public function ${enclosing_type}(enforcer:SingletonEnforcer) {}
public static function getInstance():${enclosing_type}
{
if (${enclosing_type}.__instance == null)
__instance = new ${enclosing_type}( new SingletonEnforcer() );
return __instance;
}
}
}
class SingletonEnforcer {}