23 May 2011
Beginning
In this exercise you will create a skin for the Employee Portal application and use the provided skinning components to configure the application so that it appears as shown in Figure 1.
In this exercise, you will learn how to:
In this section, you will use Flash Builder to create a skin for the Employee Portal application.
The ApplicationContainerSkin.mxml file will open in the Editor.
SparkSkin tags, below the Declarations block, create a Metadata block:<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:SparkSkin...>
<fx:Declarations>
</fx:Declarations>
<fx:Metadata>
</fx:Metadata>
</s:SparkSkin>
<fx:Metadata>
</fx:Metadata>
</s:SparkSkin>
Metadata tags, type [H to invoke the content assist tool, select the HostComponent() function and assign the spark.components.Application package to the skin:<fx:Metadata>
[HostComponent("spark.components.Application")]
</fx:Metadata>
The HostComponent metadata tag identifies the host component of a Spark skin class. As a result of this definition, you can access the public members of the host component's instance from within the skin. In other words, in this case, you can access the properties of the Application tag. You will learn how to use component properties in a later video and exercise.
Metadata tag block, add a states tag block:...
</fx:Metadata>
<s:states>
</s:states>
states block, add a State instance and add the name property with a value of normal:<s:states>
<s:State name="normal"/>
</s:states>
State instance, add another State instance and add the name property with a value of disabled:<s:states>
<s:State name="normal" />
<s:State name="disabled" />
</s:states>
states block, add a Rect tag block: ...
</s:states>
<s:Rect>
</s:Rect>
Rect tag, assign the width property value to 848, the height property value to 600, and the x and y property values to 0:<s:Rect width="848" height="600" x="0" y="0">
</s:Rect>
Rect tag, add the radiusX and radiusY properties, each with a value of 10.<s:Rect width="848" height="600" x="0" y="0" radiusX="10" radiusY="10">
</s:Rect>
Rect tags, add a fill property block.<s:Rect width="848" height="600"
x="0" y="0"
radiusX="10" radiusY="10">
<s:fill>
</s:fill>
</s:Rect>
fill tags, add a SolidColor instance with the color property value assigned to #CCCCCC/li><s:fill>
<s:SolidColor color="#CCCCCC"/>
</s:fill>
In this section you will apply the ApplicationContainerSkin component to the Employee Portal application.
Application tag, assign the skinClass property value to skins.ApplicationContainerSkin.<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"
xmlns:components="components.*"
skinClass="skins.ApplicationContainerSkin">
You should see a gray rectangle with rounded corners, which will be the skin for the application (see Figure 4). Note that none of the content is displayed in the application.
In this section, you will use a Flex container control to display the Employee Portal application through the ApplicationContainerSkin skin.
Rect tag, create a Group container and assign the id property value to contentGroup:</s:Rect>
<s:Group id="contentGroup">
</s:Group>
You should see the Employee Portal application is now visible, but is not centered in the browser (see Figure 5).
Rect tag, remove the x and y properties.horizontalCenter and verticalCenter properties to the Rect tag with a value of 0. This will constrain the application background to the center of the browser.<s:Rect width="848" height="600"
radiusX="10" radiusY="10"
horizontalCenter="0" verticalCenter="0">
You should see that the gray application skin is now centered in your browser. Also notice that when you resize your browser, the skin remains centered within your browser, but the content does not stay centered (see Figure 6).
Group tag, assign the horizontalCenter and verticalCenter properties a value of 0. This will constrain the application content to the center of the browser.Note that the application content is constrained to the center of the browser, but the content does not look centered. This is because padding was previously added to the static position values so that the content did not start at a position of x="0" and y="0" (see Figure 7).
HGroup tag, change the x and y values to 0.components:EmployeeOfTheMonth tag, change the x value to 0. Leave the y value since you will be adding a title bar later which needs the extra space.components:EmployeeDirectory tag, change the x value to 0.components:Cafeteria tag, change the x value to 275.components:MonthlyEvents tag, change the x value to 550.LOGOUT Button control, change the x value to 710.You should now see that both the application skin and the content are constrained to the center of the browser (see Figure 8).
Currently the ApplicationContainerSkin is hardcoded to a specific height and width value. If you make changes to the content, the skin will not resize automatically. Next you will make the ApplicationContainerSkin reusable by nesting and constraining the gray background rectangle and the contentGroup container instance inside of a new Group container.
Rect control and the contentGroup container with a Group container.horizonalCenter and verticalCenter properties from the opening Rect and contentGroup tags.Group container, add the horizontalCenter and verticalCenter properties with a value of 0.Rect tag, remove the width and height properties.left, right, top, and bottom properties to the Rect tag with a value of 0. This will constrain the rectangle zero pixels to the left, right, top and bottom of the parent Group container.contentGroup container, add the left, right, top, and bottom properties with a value of 30. This constrains the contentGroup container to 30 pixels to the to the left, right, top, and bottom of the parent Group container.<s:Group horizontalCenter="0" verticalCenter="0">
<s:Rect left="0" right="0" top="0" bottom="0"
radiusX="10" radiusY="10">
<s:fill>
<s:SolidColor color="#CCCCCC"/>
</s:fill>
</s:Rect>
<s:Group id="contentGroup"
left="30" right="30" top="30" bottom="30">
</s:Group>
</s:Group>
You should see that the application skin now has a 30-pixel border around the content (see Figure 9).
In this section, you will apply a skin to the EmployeePortal header image.
Note that the TopContainerSkin.mxml contains code similar to the code in the ApplicationContainerSkin.mxml file.
To make the title bar skinnable, you will replace the HGroup container with a SkinnableContainer container.
HGroup tags to SkinnableContainer tags.SkinnableContainer tag, assign the skinClass property value to skins.TopContainerSkin.<s:SkinnableContainer x="0" y="0"
gap="15"
skinClass="skins.TopContainerSkin">
Note that there is a compile error that reads, "Cannot resolve attribute 'gap' for component type spark.components.SkinnableContainer." This error occurs because the SkinnableContainer does not support the gap property.
SkinnableContainer tag, cut the gap property.layout tags within the Group container.HorizontalLayout tag, paste the gap property.<s:Group id="contentGroup"
verticalCenter="0"
left="20">
<s:layout>
<s:HorizontalLayout gap="15"/>
</s:layout>
</s:Group>
The header of the Employee Portal application now has a blue background (see Figure 10).
In this section you will skin the application using a skin component and a CSS file.
Note that the code is similar to the code within the ApplicationContainerSkin.mxml file you created earlier.
Spark Panel containers.backgroundColor property and value and use the classReference() function to assign the skinClass property value to the skins.PanelContainerSkin component.s|Panel
{
skinClass:ClassReference("skins.PanelContainerSkin");
}
You should see that the panels are skinned, but the panel titles begin in the red box (see Figure 11).
titleDisplay Label control, change the left property value to 35. This will shift the panel title to the right of the red box.Label tag, add a color property and assign a value of #FFFFFF. This will change the panel titles to white.<s:Label id="titleDisplay"
lineBreak="explicit"
left="35" right="4" top="2"
height="30"
verticalAlign="middle"
fontWeight="bold"
color="#FFFFFF"/>
You should see the panel titles are white and display to the right of the red box (see Figure 12).
SkinnableContainer tag.Label tag with the text property of Employee, add a color property and set the value to #FFFFFF.Label tag with the text property of Portal, add a color property and set the value to #FFFFFF.You should see the application as shown in Figure 13. Note that the Employee Portal heading is now white.
Panel selector, comment out the skinClass:ClassReference.EmployeeOfTheMonth components tag, add the skinClass property with a value of skins.PanelContainerSkin.Cafeteria and MonthlyEvents component tags.You should see that all of the panels are skinned except for the Employee Directory panel. Notice that the background color for the Employee Directory panel is white (see Figure 14).
EmployeeDirectory component instance, add a backgroundColor property with a value of #E8E8E8.You should now see that the Employee Directory panel has a background color even though it is not skinned like the other panels (see Figure 15).
In this section you will learn how to use a Flash XML Graphic (FXG) file to style components in Flash Builder.
The TopSkin.fxg file was created using Adobe Illustrator CS5. The file opened in Illustrator CS5 appears as shown in Figure 16. Note that the only rounded corner is the top right corner.
Rect block.Rect tags, add a skins tag for the TopSkin file. The skins namespace is used to add the TopSkin.fxg file to the application. You'll notice that when you added the skins tag, a skins namespace was added to the skin class.<skins:TopSkin/>
You should see that only the top right corner of the SkinnableContainer container skin is curved (see Figure 17).
In this exercise you created a skin for the Employee Portal application and used the provided skinning components to configure the application. In the next exercise you will create a custom skin property and reuse it to style a Panel container skin with differently colored highlights.
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.