views:

29

answers:

1

Hi I am new new to flex development. I am building a flex application which uses rest APIs.

Right now I have created different for different API calls (login, logout, search etc.) And all these services are in main mxml application file.

I am wondering if I can create a separate mxml file like services.mxml that I can use to call any service.

Is this the right approach? And can you tell me how t do this?

Thanks

Priyank

+1  A: 

Yes, you can encapsulate Flex code so it is not all in the same file. Yes, you can also do this with services. In fact the Cairngorm framework uses that exact approach. [And I assume other frameworks do too].

When you create a component architecture the trick is figuring out how components communicate with each other. In Flex, a component can dispatch events to communicate with it's parent. And it can have methods or properties so the parent can communicate with the child.

Encapsulating all services to a single is fine, but you'll need to figure out components will access those services and how those services will send results back to the components. It's not a simple proposition.

I think you need to research the flex component lifecycle a bit and read up on creating Flex Components or ActionScript classes.

Here are a few resources:

http://www.adobe.com/devnet/flex/components.html http://www.adobe.com/devnet/flex/articles/creating_components.html http://livedocs.adobe.com/flex/3/html/help.html?content=Part4_CreateComps_1.html

www.Flextras.com
A best practice article for the mate-framework could be found here: http://mate.asfusion.com/page/documentation/best-practices/service-invokers
hering