O'Reilly logo

Professional Adobe® Flex® 3 by Joe Berkovitz, David Hassoun, Andrew Trice, Tom Sugden, Todd Prekaski, Jun Heider, Peter Ent, Joseph Balderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required