Flex 3 had some language tags we are all familiar with like <fx:Binding>, <fx:metadata>, <fx:script> and <fx:style> to name a few.
Flex 4 introduces some new mxml tags you can use when writing mxml classes. They are <fx:Declarations>, <fx:Definition>, <fx:Library>, <fx:Private> and <fx:Reparent>.
The <fx:Declarations> tag is used to declare non-visual, non-default properties of the mxml class, but can also be used to declare default properties.
Note, that these types will produce compilation errors if declared outside the <fx:Declarations> tag.
Some examples (not a complete list) are:
* Basic classes (String, Boolean, Double, etc)
* Data sets (Array, ArrayCollection, XMLList, Vector, etc)
* Simple data models (fx:Model, fx:XML)
* RadioButtonGroups (not the radio buttons themselves)
* Inline renderers (treated as default properties)
* RPC components (WebServices, HTTP Services, Remote Objects)
The <fx:Definition> tag is used to define graphical children that can later be used in other parts of the application. Definition tags MUST be defined within a <fx:Library> tag. It must define a name attribute for reference as the tag name when instantiating the element.
It is similar to a private inline class, and in fact each definition is compiled into a seperate AS class that is a subclass of the first node of the definition. Instances of it are created when referenced outside of the <fx:Library> tag scope, and only then they are instantiated and added to the display list. It is also used with FXG, which we will cover in a future post.
We use the <fx:Library> tag to define any number of <fx:Definition> children. As described above, the definition itself is not an instance, but it allows you to make instances of it anywhere in the document.
The <fx:Library> tag MUST be the first tag right after the root tag, and only one can be defined per document.
The <fx:Private> tag provides meta information about the MXML or FXG document. The tag must be a child of the root document tag, and it must be the last tag in the file.
The compiler ignores all content of the <fx:Private> tag, although it must be valid XML. The XML can be empty, contain arbitrary tags, or contain a string of characters.
The <fx:Reparent> tag lets you specify an alternative parent to a child node, as part of a specific state.
We will cover this in length in the post about the new states mechanism introduced with Flex 4, but the general syntax is:
<fx:Reparent target=”targetComp” includeIn=”stateName”>
The target property specifies the target component, and the includeIn property specifies a view state. When the current view state is set to stateName, the target component becomes a child of the parent component of the <fx:Reparent> tag. You can think of the <fx:Reparent> tag as a placeholder for the component for a specific view state.
I attached some sample code. Note, that the sample for <fx:Definition> and <fx:Library> is the same one.
You can get it here (right click + save as…).