View Single Post
  #1 (permalink)  
Old 02-08-2008, 08:02 AM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 317
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
Icon11 An easier Flash AS3 Singleton

Here's an easier version of the singleton class - similarly used in the Caingorm framework for AS3. The key is that the constructor is void and doesn't allow instantiation of itself

Code:
 package com.layeronemedia {
    
    /**
     * One-Instance enforced singleton that instantiates and contains the data
     * as a DataCollection and the controls as the ControlCollection.
     */
    public class Controller {
        private static var _instance:Controller;
        
        /**
         * Public static method to instantiate the Controller object.
         * @return Controller Object Instance
         */
        public static function getInstance():Controller {
            if (_instance == null) {
                _instance = new Controller();
            }
            return _instance;
        }
        
        
        public function Controller():void {
            _Do all your Stuff Here
        }
    }
}
Reply With Quote
The Following User Says Thank You to ccoonen For This Useful Post:
HelloWorld (02-08-2008)