Oops wrong key...
The code is opensource so you can see how it works... here's the call it makes. (This is cairngorm v2) /** * Return the WebService for the given service id. * @param serviceId the service id. * @return the RemoteObject. */ public function getWebService( serviceId : String ) : WebService { return WebService( getServiceForId( serviceId ) ); } /** * Return the service with the given id. * @param serviceId the id of the service to return. * @return the service. */ private function getServiceForId( serviceId : String ) : Object { if ( this[ serviceId ] == null ) { throw new CairngormError( CairngormMessageCodes.NO_SERVICE_FOUND, serviceId ); } return this[ serviceId ]; } And when you look at the code... it grabs the instance of your service from the ServiceLocator.mxml file. For example: <YourServiceLocatorSubClass>.getInstance().loginService; which equals this[ "loginService" ] which equals this.loginService. It's just a fancy way of saying this.loginSevice where this is <YourServiceLocatorSubClass>. You used to be able to simply include the cairngorm framework code and step through it... it's a little trickier now that they're using resource bundles. The ServiceLocator class is a singleton as well. You will only EVER have one in your application so even though you are creating a subclass as soon as you call getInstance() you will get the only instance there is in your application. If you had two Services.mxml files (Service1.mxml and Services2.mxml) in your app the last one created would be the one returned by ServiceLocator.getInstance(); Hope that helps. p.s. Is it true that Bell Canada has been using Flex since it was Royale? I used to live in Calgary so just curious. ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Friday, January 05, 2007 10:53 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Cairngorm ServiceLocator I'm a little confused. How come I can ask com.adobe.cairngorm.business.ServiceLocator for a service from an MXML component which is a "sub-class" of ServiceLocator? i.e.: Services.mxml: <cairngorm:ServiceLocator ...> <mx:WebService name="myService" ... /> </cairngorm:ServiceLocator> var theService = ServiceLocator.getInstance().getWebService("myService"); How does ServiceLocator know what a "myService" is? It's not defined in ServiceLocator.as. It works, I just don't understand why... What is the relationship between an MXML file and an AS class that makes this happen? Jay Proulx Application Developer Internet Delivery Services - eVision Team [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> (613) 783-6711