23 May 2011
Beginning
In Day 4 you created a Spark item renderer, which you applied to the repeated data elements in the DataGroup container. You added some visual enhancements to the item renderer but not to the DataGroup container itself.
In this exercise you will change the DataGroup container to a SkinnableDataContainer container so that you can apply a skin to it (see Figure 1). It is the gray rounded rectangle around all of the employee data elements.
You will also create a new hover state display for the items.
In this exercise you will learn how to:
In this section you will change the DataGroup container (used in Exercises 4.1 and 4.2) to a SkinnableDataContainer container so that you can apply a skin to it.
You should see the application appears as shown in Figure 2. The item renderer used for the data in this application was created in Exercise 4.2: Displaying dynamic data in a custom item renderer.
UI components comment, locate the DataGroup container.DataGroup container into a SkinnableDataContainer component.<s:SkinnableDataContainer dataProvider="{employeeList}"
itemRenderer="components.EmployeeItemRenderer"/>
You should see no change in the application.
In this section, you will create a skin and apply it to the SkinnableDataGroup container.
SkinnableDataContainer tag and switch to Design mode.
You should see the BackgroundSkin.mxml file open in the Editor view.
SkinnableDataContainer class as its host component class. It also contains a states block with the required State tags and a DataGroup container.Remember that containers like the Group, Application, and Panel container have a skin part named contentGroup. For the DataGroup container, the skin part is named dataGroup.
states block, create a Rect primitive block.<s:states>
<s:State name="normal" />
<s:State name="disabled" />
</s:states>
<s:Rect>
</s:Rect>
Rect primitive, add the height property with a value of 100%, the width property with a value of 120 and the radiusX and radiusY properties, both with a value of 4.<s:Rect height="100%" width="120" radiusX="4" radiusY="4">
</s:Rect>
Rect block, create a fill block.<s:Rect height="100%" width="120" radiusX="4" radiusY="4">
<s:fill>
</s:fill>
</s:Rect>
fill block, create a SolidColor graphic and add the alpha property with a value of .4 and the color property with a value of 0x000000.<s:Rect height="100%" width="120" radiusX="4" radiusY="4">
<s:fill>
<s:SolidColor alpha=".4" color="0x000000"/>
</s:fill>
</s:Rect>
SkinnableDataContainer container, note that the skinClass property has been added with a value of skins.BackgroundSkin.<s:SkinnableDataContainer dataProvider="{employeeList}"
itemRenderer="components.EmployeeItemRenderer"
skinClass="skins.BackgroundSkin"/>
You should see the skin applied to the SkinnableDataGroup container (see Figure 5). Note that the content is not centered within the skin.
DataGroup container, add the horizontalCenter property with a value of 0.<s:DataGroup id="dataGroup"
...
horizontalCenter="0">
...
</s:DataGroup>
DataGroup container, remove the left, right, and top properties.DataGroup container, reassign the bottom property with a value of 5.The data is now centered within the skin (see Figure 6). Note that when you mouse over an employee there is a small rectangle that indicates you are hovering over an item. This occurs because you have set the top property in the BorderContainer of the EmployeeItemRenderer class. Next, you will modify the hovered state of the item renderer.
In this section you will create the hover state for the content in the DataGroup container.
BorderContainer and cut the top property from the opening tag.top property into the opening tag from the DataGroup container.bottom property to 5.<s:DataGroup id="dataGroup"
top="5" bottom="5"
minWidth="0" minHeight="0"
horizontalCenter="0">
Note that the rectangle you saw before is now gone.
states block.normal State tag, add another instance of the State tag and add the name property with a value of hovered.<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
</s:states>
BorderContainer block. This container draws the background for each item renderer and also displays the employee data.BorderContainer instance, create a Rect instance with a height value of 100% and a width value of 100%. This will create a rectangle that will completely overlay the item renderer.<s:Rect height="100%" width="100%">
</s:Rect>
Rect block, create a fill property tag block.fill property, create a SolidColor instance and give it a color property with a value of #FFFFFF (white). This adds a highlight color when you hover over the item.<s:fill>
<s:SolidColor color="#FFFFFF"/>
</s:fill>
SolidColor instance, add the alpha property with a value of .2. This will make the highlight transparent.<s:fill>
<s:SolidColor color="#FFFFFF"
alpha=".2"/>
</s:fill>
Rect tag, add the includeIn property with a value of hovered. Without the includeIn property, the rectangle would display all the time. Now you have made sure that it only displays in the hovered state.<s:Rect height="100%" width="100%"
includeIn="hovered">
SolidColor instance within the fill block. To the color property add .hovered to make sure the color only appears in the hovered state. <s:fill>
<s:SolidColor color.hovered="#FFFFFF"
alpha=".2"/>
</s:fill>
You should see the employee is highlighted with a transparent white box (see Figure 7).
In this exercise you changed the DataGroup container to a SkinnableDataContainer container so that you can apply a skin to it. In the next exercise you use Flash Builder to create a production build of the Flash application.
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.