Posted By

Paco on 10/02/08


Tagged

Singleton as3 AS3Patterns


Versions (?)

Who likes this?

9 people have marked this snippet as a favorite

Paco
meetneps
THEPWN3R
vip4lyf
themill
chrisaiv
edsonpavoni
shuchii
tspitzr


AS3 Singleton


 / Published in: ActionScript 3
 

  1. package ###PACKAGE_PATH###
  2. {
  3. private static var _instance:###CLASS_NAME###;
  4.  
  5. public class ###CLASS_NAME###
  6. {
  7. public static function getInstance():###CLASS_NAME###
  8. {
  9. if ( !_instance )
  10. _instance = new ###CLASS_NAME###( new SingletonEnforcer() );
  11. return _instance;
  12. }
  13. public function ###CLASS_NAME###( se:SingletonEnforcer )
  14. {
  15. if ( !se )
  16. throw( new Error( "use ###CLASS_NAME###.getInstance() instead!!" ) );
  17. }
  18. }
  19.  
  20. }
  21. class SingletonEnforcer{}

Report this snippet  

You need to login to post a comment.