Chapter 17. Custom MXML Components
Flex MXML application files are nothing more than a quicker way to create ActionScript classes. The Flex mxmlc
compiler converts every MXML file into an ActionScript class file. You can see the result of this by adding -keep-generated-actionscript=true
to your compiler options.
This means that if you have been writing custom components in ActionScript, you can also write custom components in MXML, as you will see in this chapter.
MXML Versus ActionScript Components
You may be under the impression that using MXML files adds overhead — extra code and variables — that your application could do without if you were to write everything in ActionScript. That is technically true, to a degree.
For example, if you take the CompanyLogo
example from the previous chapter and put the code into a <mx:Script>
block of an MXML file using <mx:Canvas>
as the root tag, you would be correct in your assumption. Using Canvas
as the base class for such a component would add extra code as the Canvas
has code in it to help manage its children. The CompanyLogo
component has no children, so using UIComponent
as its base class makes sense.
However, if you assume that you could write the CompanyLogo
component in ActionScript and, using a Canvas
as its base class, it would be more efficient than using an MXML file, you would be wrong. In other words, it is not so much that you are using MXML files versus ActionScript files, it is using Canvas
versus UIComponent
as the base class ...
Get Professional Adobe® Flex® 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.