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

时光怂恿深爱的人放手 提交于 2019-12-23 02:01:57

问题


I find it much easier to write MXML classes with embedded Script than trying to make an actionscript file.

I was wondering however what kind of overhead there is of using an MXML file - in terms of file size. I'm not especially concerned about performance, but if that is relevant would be interested in any findings.

Obviously I'm talking about UI components that have layout. MXML is MUCH easier to visualize and modify but I'm unclear exactly what it compiles down too. I'm hoping there is a negligible difference.


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/264043/what-overhead-is-there-of-using-an-mxml-file-in-flex-vs-a-plain-actionscript-cl

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