开发者

How to handle large MXML file

I am currently working on the largest Flex / Flash Builder 开发者_StackOverflow中文版4 application I have ever built. I am acustomed to keeping all of my MXML programming in one file. What are some best practice procedures for keeping large MXML files readable?


I am acustomed to keeping all of my MXML programming in one file.

I suggest you get out of that habit as soon as possible. You won't end up with maintainable code in the long term. A one file app is probably not going to be maintainable long term.

Most people split things up into components; and then use those components in the main application. How you split up the components depends greatly on what you're trying to accomplish. Some may use a ViewStack, with each child being a custom component. Ohers may use states with a similar approach. Often components have components as children, and it drills down to having a lot of nested files. But, this is much more maintainable than a single file.


I would highly recommend adopting a framework, and especially one that supports modules. There is an example of a module being used here that is good.

As far as frameworks go, I'd highly recommend the 1.0 release of Swiz. The awesome part about Swiz now is that it supports dependency injection at the local level into modules. This is not something that was available in the previous versions and also is not supported in other older frameworks like Cairngorm. Swiz should really let you rip apart and modularize your program quite a bit if you follow the framework correctly.


  1. You could use code behind to separate any AS3 you have written into a different file.
  2. Beyond that if your file is excessively long I would suggest breaking it into distinct components and replacing your megafile with instances of those components.

How many lines is this file?


I would recommend separating that 1500 line MXML file into separate components or modules if that's appropriate for your application.

Personally, I use Mate to keep my display components separate from my back end data. It lets you inject your data and properties into whichever components you need.

Try to isolate specific functionality (search, login, record entry, etc.) in your application into its own component. This way you can easily reuse it in other areas as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜