23 May 2011
Beginning
In this exercise you will create a custom skin property and reuse it to style a Panel container skin with differently colored highlights (see Figure 1).
In this exercise, you will learn how to:
In this section, you will change the color of the title bar for each of the Panel containers within the Employee Portal application.
components namespace and comment them out.
The EmployePortalPanel.mxml file will open in the Flash Builder Editor view.
Declaration tag block and create a Script block.Script block, type panelTitleColor and press CTRL+1 to invoke the quick assist tool. Select the Create instance variable option. This will create a private variable named panelTitleColor data typed to the Object class.public and modify the data type to the uint class.<fx:Script>
<![CDATA[
public var panelTitleColor:uint;
]]>
</fx:Script>
EmployeePortalPanel component tag block.EmployeePortalPanel component opening tag, assign the title property value to EMPLOYEE OF THE MONTH.panelTitleColor property to the EmployeePortalPanel tag and give it a value of #64BC48 (green).EmployeePortalPanel component tag set, add an instance of the EmployeeOfTheMonth component.<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH"
panelTitleColor="#64BC48">
<components:EmployeeOfTheMonth/>
</components:EmployeePortalPanel>
You will see only one panel that is not properly positioned. You will fix that later. However, note that there are two panel title areas for the Employee of the Month panel (see Figure 4). This occurs because each component is based on the Panel container.
Panel container to a Group container.Group container tag, reassign the width and height properties to a value of 100%.<s:Group xmlns:fx=http://ns.adobe.com/mxml/2009
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" height="100%">
EmployeeOfTheMonth component instance, copy the x, y, and skinClass properties and their values and paste them into the opening EmployeePortalPanel component instance.EmployeePortalPanel component instance, add the height property with a value of 295.<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH"
panelTitleColor="#64BC48"
x="0" y="95"
skinClass="skins.PanelContainerSkin"
height="295">
You should see that only the Employee of the Month panel is displayed and the color block of the panel's title bar has not changed (see Figure 5).
In this section you will create a function to handle the passing of the panelTitleColor property value from the main application file to the custom component.
Rect tag block that follows the PanelSkin instance.SolidColor tag, remove the color property value:<s:fill>
<s:SolidColor/>
</s:fill>
SolidColor tag, assign the id property to headerSkinColor:<s:fill>
<s:SolidColor id="headerSkinColor"/>
</s:fill>
MetaData tags.HostComponent() function, change the value to reference the EmployeePortalPanel component:<fx:Metadata>
[HostComponent("components.EmployeePortalPanel")]
</fx:Metadata>
Script comment and add a Script block below it:<!-- Script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<fx:Script>
<![CDATA[
]]>
</fx:Script>
...
Script block, create a private function named initTitleSkin that returns a void data type:<fx:Script>
<![CDATA[
private function initTitleSkin():void
{
}
]]>
</fx:Script>
initTitleSkin() function, assign the color property of the headerSkinColor SolidColor fill to the hostComponent.panelTitleColor property value:private function initTitleSkin():void
{
headerSkinColor.color = hostComponent.panelTitleColor;
}
SparkSkin tag, assign the creationComplete property value to call the initTitleSkin() function:<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="initTitleSkin()">
You should see that the color block in the Employee of the Month panel is now green (see Figure 6).
EmployeePortalPanel component and paste two instances below the first.<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH"
panelTitleColor="#64BC48"
x="0" y="95"
skinClass="skins.PanelContainerSkin"
height="295">
<components:EmployeeOfTheMonth/>
</components:EmployeePortalPanel>
<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH"
panelTitleColor="#64BC48"
x="0" y="95"
skinClass="skins.PanelContainerSkin"
height="295">
<components:EmployeeOfTheMonth/>
</components:EmployeePortalPanel>
<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH"
panelTitleColor="#64BC48"
x="0" y="95"
skinClass="skins.PanelContainerSkin"
height="295">
<components:EmployeeOfTheMonth/>
</components:EmployeePortalPanel>
EmployeePortalPanel component, reassign the title property to CAFETERIA SPECIAL, the panelTitleColor property value to #F05123 (orange), and the x property value to 275.height property and and change the nested component to the Cafeteria component.<components:EmployeePortalPanel title="CAFETERIA SPECIAL"
panelTitleColor="#F05123"
x="275" y="95"
skinClass="skins.PanelContainerSkin">
<components:Cafeteria/>
</components:EmployeePortalPanel>
EmployeePortalPanel component, reassign the title property to MONTHLY EVENTS, the panelTitleColor property value to #0D86B8 (blue), and the x property value to 550.height property and change the nested component to the MonthlyEvents component.<components:EmployeePortalPanel title="MONTHLY EVENTS"
panelTitleColor="#0D86B8"
x="550" y="95"
skinClass="skins.PanelContainerSkin">
<components:MonthlyEvents/>
</components:EmployeePortalPanel>
Since the EmployeeDirectory component does not use the PanelContainerSkin, you do not need to nest it within an EmployeePortalPanel component instance.
You should see the Employee of the Month, Cafeteria Special, and MonthlyEvents panels have different colored headers (see Figure 7). Also note that the text in the Monthly Events panel is blue.
MonthlyEvents selector and comment out the color property.You should see that the text within the Monthly Events panel is now black (see Figure 8).
In this exercise you created a custom skin property and reused it to style a Panel container skin with different colored highlights. In the next exercise you will learn how to use a skin to make the Panel container title bar vertical.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.