如何处理大型 MXML 文件
我目前正在开发我曾经构建过的最大的 Flex / Flash Builder 4 应用程序。我习惯于将所有 MXML 编程保存在一个文件中。保持大型 MXML 文件可读的最佳实践过程有哪些?
I am currently working on the largest Flex / Flash Builder 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议将 1500 行 MXML 文件分成单独的组件或 模块(如果适合您的应用程序)。
就我个人而言,我使用 Mate 将显示组件与后端数据分开。它允许您将数据和属性注入到您需要的任何组件中。
尝试将应用程序中的特定功能(搜索、登录、记录条目等)隔离到其自己的组件中。这样您就可以根据需要轻松地在其他区域重复使用它。
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.
我建议你尽快改掉这个习惯。从长远来看,您最终不会得到可维护的代码。单文件应用程序可能无法长期维护。
大多数人将事物分解为多个组件;然后在主应用程序中使用这些组件。如何拆分组件很大程度上取决于您想要完成的任务。有些可能使用 ViewStack,每个子组件都是一个自定义组件。其他人可以使用类似方法的状态。通常,组件将组件作为子组件,并且深入到具有大量嵌套文件。但是,这比单个文件更易于维护。
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.
我强烈建议采用一种框架,尤其是支持模块的框架。 这里有一个使用模块的示例 那很好。
就框架而言,我强烈推荐 Swiz 1.0 版本。 Swiz 现在最棒的部分是它支持在本地级别将依赖项注入到模块< /a>.这在以前的版本中是不可用的,并且在其他较旧的框架(如 Cairngorm)中也不支持。如果您正确遵循框架,Swiz 确实应该让您对程序进行相当多的拆分和模块化。
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.
这个文件有多少行?
How many lines is this file?