3 May 2011
Exercise 1.1: Setting up Flash Builder and your project files
Exercise 5.1: Using text controls
Beginning
In this exercise, you will use the Flash Builder Appearance view and cascading style sheets (CSS) to create the styles shown in Figure 1.
In this exercise, you will learn how to:
In this section, you will use the Appearance view to change the text style for the sample application.
You should see the Employee Portal page shown in Figure 2.
Note: The Appearance view is located by default next to the Properties view. If you do not see the view, select Window > Appearance.
You should see the global selector with the fontFamily property value of Verdana and the fontSize property value of 11.
Style tag that was generated when you changed the global font style.<!-- Properties of the parent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Style source=”ex5_02_starter.css”/>
<!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
Style tag from below the Properties of the parent comment and place it below the Styles comment.The Style tag will work where it was positioned, but moving it makes your code consistent with the coding convention for this video series.
<!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<fx:Style source="ex5_02_starter.css"/>
<!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
You should see application text reflects the global style selector located in ex5_02_starter.css (see Figure 5).
In this section you will use a CSS selector to set the background color for all the Panel containers within the application.
EmployeeOfTheMonth Panel container.Panel container has the backgroundColor property set to #E8E8E8.<components:EmployeeOfTheMonth title="Employee of the Month"
x="24" y="95"
backgroundColor="#E8E8E8"/>
You should see the Employee of the Month panel has a light-grey background color as shown in Figure 7.
Panel container selector that will set the background-color property value to #E8E8E8.Note: In Flex, you can use either the MXML or CSS version of the background color property—backgroundColor or background-color, respectively. If you use the content assist tool, the CSS property, background-color, will be added.
global
{
fontFamily: Verdana;
fontSize: 10;
}
s|Panel
{
background-color: #E8E8E8;
}
You should see that all of the panels now have the new background color (see Figure 8).
backgroundColor property value.<components:EmployeeOfTheMonth title="Employee of the Month"
x="24" y="95"/>
You should see there has been no visual change made to the application, meaning the component selector is working for the Panel containers.
In this section, you will use CSS to change the styles of Flex controls.
Panel container, create a CSS selector for the Button control class.s|Panel
{
background-color: #E8E8E8;
}
s|Button
{
}
color property a value of #0074AA (blue).s|Button
{
color: #0074AA;
}
Note that the label text for all of the Button controls are now blue (see Figure 9).
Button control selector, create another CSS selector for the Button control, assigning the color property value to #000000 (black).s|Button
{
color: #0074AA;
}
s|Button
{
color: #000000;
}
You should see the Button control label text is now black because the second selector is being processed due to the multiple selector rule (see Figure 10).
Button control selector, create another CSS selector for the Button control, assigning the font-family property value to Arial.s|Button
{
color: #000000;
}
s|Button
{
font-family:"Arial";
}
You should see the button label text changed to Arial (see Figure 11).
In this section, you will create a custom namespace to style the custom components within the Employee Portal.
mx namespace, use the @namespace syntax to create the namespace cx, that references the contents of the components folder.@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
@namespace cx "components.*";
Button control selector, use the cx namespace to change the color of text in the MonthlyEvents Panel container to #0B85B7 (blue).s|Button
{
font-family:"Arial";
}
cx|MonthlyEvents
{
color: #0B85B7;
}
You should see that the text color within the Monthly Events panel is now blue (see Figure 12).
color property and assign the value to #000000 (black).The text color within the Monthly Events panel is now black (see Figure 13). The property on the Panel container overrides the value set with CSS.
In this exercise you used the Flash Builder Appearance view and cascading style sheets (CSS) to create styles.
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.