In the yesterday’s post I released the source code of a Dashboard application that uses custom Spark components. Today I’ll show how to change its layout through Flex 4 skinning techniques.
Analyzing the source code you are gonna realize that this application has 2 custom Spark components: PodManager and PodWindow. Today we’ll focus in the implementation of the PodManager component, which is responsible to manage the PodWindow instances, define where it can be instantiated and for the Dashboard features.
Below you can see how to instantiate the PodManager component, define its skin class and also how you can split the PodWindow instances into two content areas, firstElements e secondElements :
<components:PodManager id="podManager" skinClass="com.rectius.examples.pod.assets.skins.PodManagerVerticalSkin" left="10" right="10" top="40" bottom="15"> ? <components:firstElements> <view:ChartExpenses width="100%" height="100%" title="Expenses" /> <view:ChartProfit width="100%" height="100%" title="Profit"/> components:firstElements> ? <components:secondElements> <view:ChartWidget width="100%" height="100%" title="Widget"/> components:secondElements> ? components:PodManager> |
And the result is the same you’ve already seen in the last post:
And If you wanna change the PodWindow’s layout, displaying it horizontally? Just do this:
<components:PodManager id="podManager" skinClass="com.rectius.examples.pod.assets.skins.PodManagerVerticalSkin" left="10" right="10" top="40" bottom="15"> ? <components:firstElements> <view:ChartExpenses width="100%" height="100%" title="Expenses" /> <view:ChartProfit width="100%" height="100%" title="Profit"/> <view:ChartWidget width="100%" height="100%" title="Widget"/> components:firstElements> ? components:PodManager> |
The above code shows that you don’t need to change the component skin to change its layout, fot that you can just intantiate all PodWindow in the same content area, into firstElements. But why the PodWindow instances are being displayed horizontally? Why don’t vertically? In order to understand it let’s analyse the skin class of the PodManager component:
<?xml version="1.0" encoding="utf-8"?> <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> -- host component --> <fx:Metadata> [HostComponent("com.rectius.examples.pod.components.PodManager")] fx:Metadata> ? -- states --> <s:states> <s:State name="normal" /> <s:State name="disabled" /> s:states> ? <s:VGroup width="100%" height="100%"> <s:HGroup id="firstContainer" width="100%" height="100%"/> <s:HGroup id="secondContainer" width="100%" height="100%"/> s:VGroup> ? s:Skin> |
The PodWindow instances are being displayed horizontally because the container firstContainer is a HGroup. Let’s turning over the PodWindow’s orientation by creating a new skin class called PodManagerHorizontalSkin :
<?xml version="1.0" encoding="utf-8"?> <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> -- host component --> <fx:Metadata> [HostComponent("com.rectius.examples.pod.components.PodManager")] fx:Metadata> ? -- states --> <s:states> <s:State name="normal" /> <s:State name="disabled" /> s:states> ? <s:HGroup width="100%" height="100%"> <s:VGroup id="firstContainer" width="100%" height="100%"/> <s:VGroup id="secondContainer" width="100%" height="100%"/> s:HGroup> ? s:Skin> |
And that’s the result:
Let’s instantiate again PodWindow components into the content area secondElements:
<components:firstElements> <view:ChartProfit width="100%" height="100%" title="Profit"/> components:firstElements> ? <components:secondElements> <view:ChartExpenses width="100%" height="100%" title="Expenses" /> <view:ChartWidget width="100%" height="100%" title="Widget"/> components:secondElements> |
And that’s the final result:
Hope you enjoy it!









