Join David Gassner for an in-depth discussion in this video Declaring meta information in MXML files, part of Flash Builder 4 and Flex 4 New Features.
The Flex 4 Compiler supports a tag called fx:Private. You can use this private element if you like to wrap arbitrarily-named elements, which constitute Private Metadata. The tags that you placed within fx: Private are ignored by the Flex Compiler, so it's a great place to put comments, information about the author, or revision history of an application or component file, or any other information that you want to store in a MXML document. For this demonstration, I'll use the application file PrivateMetadata.mxml.
I'll scroll down to the bottom of the file, and I'll place the cursor after the last visual control, but before the ending application tag. This is a required placement. The fx:PrivateMetadata tag, if used, must be placed as the last child element within the application. Now, I'll add the fx:Private element. I am going to view the code in full screen, so we can see more of it. Now, I can add as many tags within the Private element as I want.
It won't affect the final size of the application's SWF file, because all this information will be ignored during the compilation process. So, for example, I might create an <Author> element and type in my name, or I might type in an element named <Revised> and type in the current date. You can also create your own custom name spaces, so for example, I might do this. I'll create a custom namespace named dg and an element named Comments. And right within that element, I'll type in xmlns:dg="www.davidgassner.com">.
Then within that Comment element, I can type in Any Comment I want. When you save and compile your application, you should see that all the code within the fx:Private element is completely ignored. As long as your code follows well- formed XML syntax rules, it shouldn't create any compilation problems in the application. If I run the application, you'll see it behaves exactly the same as it would without the Private Metadata. But if you like, you can then write your own XML processing software to open, read and process this information in any way you like.
So, to recap, the fx:Private element is a part of the new version of MXML. It enables you to plant private metadata in an application or component file. It must be placed as the last child element within an MXML document's root element.
- Understanding MXML namespaces
- Moving classes and components between packages
- Managing templates for new MXML and ActionScript files
- Exploring MXML language changes
- Working with the Spark component framework
- Adding visual controls with CSS, MXML graphics, and custom Spark skins
- Displaying images and dynamic data