all groups > macromedia flash flash remoting > april 2006 >
You're in the

macromedia flash flash remoting

group:

bad to create more than one service?



bad to create more than one service? sneakyimp
4/20/2006 9:31:09 PM
macromedia flash flash remoting: i have a flash project constituted of multiple flash movies. each one is
creating its own instance of the exact same remoting service. i have two basic
questions.

here's the deal:

main.swf
- loads companion_products.swf
companion_products.swf
- creates a service like this: var productService:Service = new
Service(gatewayUrl, null, "products");
- waits for loaded SWFs to trigger events to load a dataGrid using the
service above
- calls 2 INSTANCES of product_list.swf
product_list.swf - each instances does the following:
- creates a service like this: var productService:Service = new
Service(gatewayUrl, null, "products");
- loads big fat product list into a data grid
- sends events to parent move to load its data grid

1) is that too many services, am i going to get into trouble? should i
consolidate those services into one service called from main.swf?

2) if so, what about when i'm developing...it's nice just to ctrl-enter on
each move to test it. in other words, what's a good consolidation technique?
Re: bad to create more than one service? jag57
4/23/2006 6:36:49 PM
I think I can answer your first question.

You could create a class and save the service in a static variable, something
like this:

class ProductService
{
public static var theService:Service;
public static function saveService(newService):Void
{
ProductService.theService = newService;
}
}

Then you can use it like this:

ProductService.saveService(new Service(gatewayUrl, null, "products"));
ProductService.theService.getData();

I'm not sure if this is the best way, but that's what I thought of first.
Another way you could do it without static variables is to create an instance
of a class (such as ProductService) that models your remote service. In the
constructor of ProductService you would create the new Service and store it in
a private variable. Then you would put some of your data access functions in
ProductService like getData, addData, etc. You could pass this around to the
different swfs.

Good luck.
Re: bad to create more than one service? sneakyimp
4/26/2006 6:14:51 PM
t's probably not a good idea to create the services in each swf. This will
lead to maintanence problems in the future if you change the name of your
service.

Is that because I would then have to edit all my individual flash files? My
thinking here was that if each SWF creates its own version of the service then
it is completely independent of the other swfs and how they choose to name
and/or deal with their own version of the service. could you elaborate? where
might i change my service name so that it applies to all swfs?

As for your class you describe below...that's kind of a new concept for me.
It appears to me as though you are still creating a new service each time you
call

ProductService.saveService(new Service(gatewayUrl, null, "products"));

To create one service and globally access it from all current SWFs, you might
as well just add this to all your SWF movies:

if (!_global.myService) {
_global.myService = new Service(gatewayUrl, null, "products");
}

and then refer in each SWF to the service as _global.myService, right?


Re: bad to create more than one service? jag57
4/26/2006 8:22:12 PM
What I'm saying is, save the service into the class once (such as in your
main.swf), then you can use it everywhere else. This is similar to your
_global example (which would work). Since the theService variable is static,
you can refer to it anywhere. If the name of your service changes, such as
from ProductService.cfc to ProductData.cfc, you can update the service creation
in one place.

Hope this helps.
AddThis Social Bookmark Button