Simple Singleton Template


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. package {
  2. public class Example {
  3. private static var instance:Example;
  4.  
  5. public function Example(access:Access){
  6. if (access != null) {
  7. if (Example.instance == null){
  8. Example.instance = this;
  9. }
  10. } else {
  11. throw new Error(”Illegal operation”);
  12. }
  13. }
  14.  
  15. //provides access to singleton instance
  16. public static function getInstance():Example{
  17. if (instance == null){
  18. instance = new Example();
  19. }
  20. return Example;
  21. }
  22. }
  23. }

URL: http://www.destroyyourcomputer.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.