由于ActionScript 3不允许构造函数为private, 因此可以用一个内部类来作为构造函数的参数,以此实现单例模式:
package { public class ModelLocator { private static var singleton:ModelLocator; public function ModelLocator(privateClass:PrivateClass) { } public static function getInstance():ModelLocator { if(singleton == null) singleton = new ModelLocator(new PrivateClass()); return singleton; } } } class PrivateClass { public function PrivateClass() { } }