1

嗨,我是 flex 开发的新手。我正在构建一个使用 REST API 的 flex 应用程序。

现在,我为不同的 API 调用(登录、注销、搜索等)创建了不同的服务,所有这些服务都在主 mxml 应用程序文件中。

我想知道是否可以创建一个单独的 mxml 文件,例如 services.mxml,我可以使用它来调用任何服务。

这是正确的方法吗?你能告诉我怎么做吗?

谢谢

普里扬克

4

1 回答 1

1

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

于 2010-09-09T21:27:20.540 回答