package{ /** */ public class MySingleton extends EventDispatcher { //---------------------------------------------------------------------- // // Private Properties // //---------------------------------------------------------------------- /** */ private static var singletonInstance:MySingleton = null; /** */ private static var constructorLocked:Boolean = false; //---------------------------------------------------------------------- // // Constructor // //---------------------------------------------------------------------- /** */ public function MySingleton() { if( constructorLocked ) { throw new Error( "MySingleton is a singleton" ); } } //---------------------------------------------------------------------- // // Public Methods // //---------------------------------------------------------------------- /** */ public function login( username:String, password:String ):void {} //---------------------------------------------------------------------- // // Getters/Setters // //---------------------------------------------------------------------- /** */ public static function get instance():MySingleton // read-only { if( singletonInstance == null ) { constructorLocked = false; singletonInstance = new MySingleton(); constructorLocked = true; } return singletonInstance; } }}
MySingleton.instance.login( ... );