From Edutechwiki - Reading time: 4 minThis entry is part of the Flex tutorials
MXML is an XML-based user interface markup language that together with ActionScript allows to develop Flash applications. MXML is considered a proprietary standard due to its tight integration with Adobe technologies, in particular Flash.
One can use the free Adobe Flex developer kit to compile MXML + ActionScript code into Flash. Flex (i.e. the combination of MXML and Actionscript) did become a fairly popular technology for developping rich internet applications (e.g. educational multimedia). Flex/mxml seems to gain popularity since it's a sort of "semi-thick client" technology and for once Adobe takes a much better political approach. Both the compiler and the documentation is open and free.
MXML allows to define
Demos:
See also: the Adobe Flex article
There don't seem to be official schemas for MXML, but some people did create schemas. In particular, check out Ali Mansuroglu's flex3.xsd or Matthias Georgi's Relax/rnc version.
Firstly, install the Flex SDK.
A Flex program is a text file that contains a combination of xml elements and optionally actionscript instructions. Here, we just focus on the MXML part.
A basic Flex 3 / mxml 2006 document would look something like this:
Files:
<?xml version="1.0" encoding="utf-8"?>
<!-- Introductory Flex 3 example, DKS, TECFA, University of Geneva, nov 2010) -->
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center" verticalAlign="middle"
width="300" height="160" >
<mx:Panel
paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"
title="My First Application" >
<mx:Label text="Hello World!" fontWeight="bold" fontSize="24"/>
</mx:Panel>
</mx:Application>
Below is a screen capture of the "application":

Files:
A similar program in Flex 4 would uses more namespaces:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="200" minHeight="100" width="200" height="100">
<s:Panel x="28" y="26"
width="200" height="100"
title="My First Application">
<s:Label text="Hello World !"
width="150" height="46"
x="21" y="10" verticalAlign="middle"
textAlign="center" fontWeight="bold" fontSize="24"/>
</s:Panel>
</s:Application>
Make sure to respect XML Syntax (e.g. closing tags).
Put the code above in text files. Save the text file as "myFirstApplication.mxml" or similar. See the "editing software" section in the Flex article if you plan to use an editor with Flex support. But for starters you can use any text editor, preferable an editor with XML support.
Assuming the Flex SDK is properly installed, in the terminal, type:
mxmlc myFirstApplication.mxml
Information appears on the screen and about half a second later, if all is well, you get informed that a file "myFirstApplication.swf" has been produced. Open this file in a flash player or in a web browser.
SWF files generated by Flex 3, require Flash Player 9 or above, files generated by Flex 4 require Flash Player 10.
As of nov 2010, this will not show in my Ubuntu in Firefox 3.6.12 and Shockwave Flash 10.1 r102 ... don't know why.
There exist several solutions for writing mxml code:
See also the Adobe Flex article
Adobe doesn't seem to provide any sort of schema that would allow you to use an XML editor. But there are some initiatives.