Return to Snippet

Revision: 13577
at April 28, 2009 11:56 by allnatural


Initial Code
package {
	public class Example {
		private static var instance:Example;
		
		public function Example(access:Access){
			if (access != null) {
				if (Example.instance == null){
					Example.instance = this;
				}
			} else {
				throw new Error(”Illegal operation”);
			}
		}
			
		//provides access to singleton instance
		public static function getInstance():Example{
			if (instance == null){
				instance = new Example();
			}
			return Example;
		}
	}
}

Initial URL
http://www.destroyyourcomputer.com

Initial Description
Easily create a SINGLE USE ONLY (Singleton) Class Object with this template.

Initial Title
Simple Singleton Template

Initial Tags
class, simple

Initial Language
ActionScript 3