> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:flashcoders- > [EMAIL PROTECTED] On Behalf Of Cédric Néhémie > Sent: Sunday, November 05, 2006 5:52 AM > To: Flashcoders mailing list > Subject: Re: [Flashcoders] OOP advice for game > > You may prefer a more common syntax for the singleton access method, > like getInstance for example.
In ActionScript (as opposed to Java), I think it's better to use a property: class Singleton { private function Singleton() { } public static function get instance():Singleton { if (_instance == undefined) { _instance = new Singleton(); } return _instance; } private static var _instance:Singleton; } // Elsewhere: Singleton.instance; // Returns the only instance of Singleton. > Personally I would prefer an EventDispatcher rather than the Observer Yes. EventDispatcher is everywhere in AS3.0, so might as well start using it now. > pattern, creating events like onWindChange, onRainChange, etc..., and a > WeatherEvent object carrying the new weather values. Generally in the code that Macromedia/Adobe writes, event names dont have "on" as part of the name, but a function responding to them might, e.g.: WeatherManager.instance.addEventListener("windChange", Delegate.create(this, onWindChange)); Or, in AS3.0: WeatherManager.instance.addEventListener("windChange", onWindChange); -- Mike Keesey _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com