What overhead is there of using an MXML file in Flex vs. a plain actionscript class?

核能气质少年 提交于 2019-12-08 20:59:31

If you're going for the same functionality, MXML is not going to make your swf any bigger.

The thing that's affecting size is using the Flex SDK and its components. Whether you declare them with MXML or AS3, you're using them and their code is being built into the swf. By the same token, if you're referencing the Flex RSL, and thus avoiding building the Flex stuff directly into your swf, it will be the same size either way. Data Binding does create a lot of events and listeners, so that might cause some bloat, but not any more than if you declared the data binding mechanism with the AS3 utility functions.

Since MXML does generate intermediate AS3 code, it might be more verbose than you would care to write on your own, so you could see some additional size from that. To peek at it (which is good for understanding in general) you can look at with the compiler directive to keep the generated code.

From: http://www.flashguru.co.uk/flex-2-compilation-hidden-goodies

  1. Right-click a Flex Project in the Navigator Panel.
  2. Select Properties from the Context Menu.
  3. Select Flex Compiler in the Properties Window.
  4. Enter -keep-generated-actionscript into the ‘Additional compiler arguments’ field.
  5. Click ‘OK’ to apply the changes.
  6. Build your Flex Project by clicking the Run button.
  7. Right-click your Flex Project again in the Navigator Panel.
  8. Choose Refresh from the Context-Menu.
  9. A new folder should appear under your Flex Project in the Navigator Panel, named ‘generated’

This is a good thing to do once you get into debugging and profiling your project, since you can really see where the compiler is doing the right (or wrong) thing.

Including the Flex framework (whether via MXML or pure Actionscript) will significantly increase the size of your final SWF.

I've just written a flash movie that consists of a single button. The MXML version was 175K while the no-Flex Actionscript version was 2K.

Though I'm not using it myself, this project seems promising for getting (some) Flex functionality with a lot less bloat:

http://code.google.com/p/e4xu/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!