Creating Custom Components with MXML
When you start building applications in Flex, it won't take you long to find that you need to build your own components. Flex makes this process relatively painless. Here is how you can create your own components in a few easy steps.
Usually, when you're building your own components in MXML, you start off by extending an existing component. As an example, let's create a customized menu bar component that contains specific menus. Extending
The first thing we'll do is create a brand new MXML file called MyMenuBar.xml. This MXML file will contain our customized menu bar. We mentioned above that we would extend an existing component. Although its fairly obvious how to do this in Actionscript; how do we accomplish the same effect with MXML? By making one of the first lines in your MyMenuBar.xml file the component we're extending. See below.
<?xml version="1.0" encoding="utf-8"?>
<mx:MenuBar xmlns:mx="http://www.adobe.com/2006/mxml">
As you see above, we use the mx:MenuBar tag, and give it an XML name space attribute similar to the same attribute we would give our mx:Application tag inside our main application file.
We could then create our menu bar the way we would normally:
<mx:XMLListCollection id="MenuBarXMLListCollection">
<mx:XMLList id="MenuBarXMLList">
<menuitem label="File">
<menuitem label="Print..." />
<menuitem label="Properties..." />
</menuitem>
etc.
</mx:XMLList>
</mx:XMLListCollection>
</mx:MenuBar>Creating a custom XML namespace
Often you'll want to group your components in a specific folder. For the sake of example, we'll say that we've grouped all of our components in a folder called 'Components' in a subfolder of the folder containing our main Flex application file. How do we go about using this new component from inside our main application?
This is easy-we'll create a custom XML namespace. This is basically similar to the namespace that you place in your mx:Application tag normally. See below.
xmlns:My="Components.*"
The above XML namespace maps a prefix 'My' to the MXML files in a specific subfolder (in this case 'Components'). We can then reference the MyMenuBar.mxml component rather easily:
<My:MyMenuBar />
With a couple of simple steps, you'll find building custom MXML components in Flex to be a breeze!
Read more...
Most web sites (or web pages) have an associated icon. Called a 'Favicon' (short for 'favorites icon'), browsers display this icon in the address bar, along with your tab (if you are using a browser with a multi-tab interface) and in your favorites (or bookmarks) list.