CoreMedia Content Cloud v11 Upgrade Guide / Version 2110
Table Of Contents
MXML is, like the name suggests, an XML format. This is also the file extension used, so the following example would
be located in acme/MyMxmlClass.mxml
. Let's have a look at its basic structure:
<?xml version="1.0" encoding="UTF-8"?> <!--- Class documentation, corresponds to /** .. */. --> <acme:MyClass xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:exml="http://www.jangaroo.net/exml/0.8" xmlns="exml:ext.config" xmlns:acme="acme.*" configOption1="foo" configOption2="{41 + 1}"> <fx:Script><![CDATA[ public static const xtype:String = "acme.myMxmlClass"; private var config: MyMxmlClass; public native function MyMxmlClass(config: MyMxmlClass = null); ]]></fx:Script> <fx:Declarations> <!--- Config option 3 documentation. --> <fx:String id="configOption3">default value for 3</fx:String> </fx:Declarations> <!-- complex Config property values are specified as nested elements: --> <acme:items> <!-- multiple elements result in an Array: --> <exml:Button id="myButton" label="Click me!"/> <exml:Separator/> </acme:items> <acme:plugins exml:mode="append"> <acme:MyPlugin .../> </acme:plugins> </acme:MyClass>
Example 7.22. Example MXML file
This example defines an ActionScript class MyMxmlClass
in MXML:
Several namespaces are declared to access ActionScript packages (
"acme.*"
) and so-called libraries (URL format). Libraries aggregate several classes from different packages and may define an alias for the class name (to prevent name-clashes).MyMxmlClass
inherits fromMyClass
- this is specified by usingMyClass
as its root node.Config properties are given as either XML attributes (
configOption1
,configOption2
) or as XML sub-elements (<acme:items>
,<acme:plugins
>).Interpolations are used to compute property values. They use curly braces
{ ... }
that can contain arbitrary ActionScript expressions.The
<fx:Script>
element contains additional class members as ActionScript code. "Real" Flex MXML may not define a custom constructor, but to declare an Ext JS specific constructor signature, receiving theconfig
argument, it is possible to declare anative
constructor. To be able to access thisconfig
parameter in interpolation expressions, it is re-declared as a "virtual" field. Since you cannot define static members in declarative MXML, the script block is also used to set the component'sxtype
.Additional class fields can be declared and/or initialized using the
<fx:Declarations>
element. Theid
attribute specifies the name of the field. The initial field value is given like any other MXML element, that is the type or class to instantiate is determined through the element name, and the value or the constructor parameter's Config properties are given as XML attributes or sub-elements. If a field with the given name already exists (either inherited or defined in the<fx:Script>
block), only this initial value is used and assigned to the existing field in generated constructor code.Finally, there is a Jangaroo addition to MXML, the property element attribute
exml:mode
. Together with utility functions in classnet.jangaroo.exml.Exml
, it takes care of the given array value being appended or prepended to the property's current value, rather than replacing it (see Section 7.3.1.6.3.4, “Merging Config Objects”).