I use .instance (accessor) instead of getInstance(). No reason not to in AS3. The only reason it's getInstance() really is that that's the Java singleton convention, and that's where a lot of pattern-aware coders started out...
Ian On Wed, Jan 21, 2009 at 3:35 PM, allandt bik-elliott (thefieldcomic.com) <alla...@gmail.com> wrote: > Does anyone know of any reason not to use an accessor in my singleton > instead of a function? > > so would this work okay (bearing in mind - as2) > > class com.publicis.hp.NavData > { > private static var _instance:Data; > > public var myVar:String; > > private function Data() > { > trace("This class is a singleton to hold data, please use > Data.instance"); > } > > public static function get instance():Data > { > if (!Data._instance) > Data._instance = new Data(); > > return Data._instance; > } > } > > rather than using > > public static function getInstance() > > The reason i ask is that i would find it neater to use it > > ie: > var myString = Data.instance.myVar; > > rather than > > var myString = Data.getInstance().myVar; > > thanks > a > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders