This a modified version of Jeff Tapper's singleton DataManager class for AS3 web service calls. Francis, note the private class constuctor at the bottom. Sorry about the jagged alignment.
- Tim Hoff package code.business { import mx.managers.CursorManager; import flash.events.EventDispatcher; import mx.rpc.soap.WebService; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.rpc.AbstractOperation; import mx.controls.Alert; import flash.util.*; public class DataServices extends EventDispatcher { private var ws:WebService; private static var instanceMap:Object = new Object(); public function DataServices(pri:PrivateClass, wsdl:String) { this.ws = new WebService(); ws.wsdl = wsdl; ws.loadWSDL(); ws.useProxy = false; } public static function getDataService (wsdl:String):DataServices { if(DataServices.instanceMap[wsdl] == null) { DataServices.instanceMap[wsdl] = new DataServices (new PrivateClass(),wsdl); } var ds:DataServices = DataServices.instanceMap[wsdl]; if(ds.ws.canLoadWSDL()) { return ds; } else { throw new Error("BAD WSDL:"+wsdl); } } public function makeRemoteCall (methodName:String,showBusyCursor:Boolean,args:Object):void { var op:mx.rpc.AbstractOperation = ws[methodName]; if(showBusyCursor) { CursorManager.setBusyCursor(); } ws.addEventListener("result",onResult); ws.addEventListener("fault",onFault); if(args) { op.arguments = args; } op.send(); } private function onResult(result:ResultEvent):void { CursorManager.removeBusyCursor(); this.dispatchEvent(result); } private function onFault(fault:FaultEvent):void { CursorManager.removeBusyCursor(); this.dispatchEvent(fault); } public override function toString():String { return "DataServices"; } } } /** PrivateClass is used to make DataServices constructor private */ class PrivateClass { public function PrivateClass() {} } --- In flexcoders@yahoogroups.com, "Francis Cheng" <[EMAIL PROTECTED]> wrote: > > That works in C# because the default access specifier for class members > in C# is private. It won't work in ActionScript 3.0 because the > constructor is always public, whether or not you declare it as such. > > Francis > > > -----Original Message----- > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] > On > > Behalf Of crnet_flex > > Sent: Friday, April 14, 2006 3:19 PM > > To: flexcoders@yahoogroups.com > > Subject: [flexcoders] Re: Singleton not usable? > > > > > > Hi > > > > Have anyone tried using a construction like the following? > > > > public class Singleton > > { > > public static const Instance:Singleton = new Singleton(); > > > > function Singleton() > > { > > } > > > > public function doSomething():void > > { > > } > > } > > > > This is actually the recommandations of creating a singleton in c#, > > and it seems that it fullfils the job here as well. > > > > I know that, if you use flexbuilder 2 beta, then you'll get a > > warning if you leave out the scope of the constructor, but maybe > > it's worth it. > > > > By the way, be aware that the singleton posted initially as an > > example is not a recommended way of creating a singleton, i guess > > it's not a problem in AS3, but lazy loaded singletons must have a > > syncronized/looked load section when thread safety is an issue. > > > > BR Casper > -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/