Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection /

Exploring Rich Island development with Flex Builder – Part 2: Laying out and styling visual elements

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Laying out visual elements
  • Styling the visual elements
  • Creating and using a CSS file
  • Embedding an image

Modified

3 August 2009

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
controls Flex 3 Flex Builder 3

Requirements

Prerequisite knowledge

Part 1: Getting started

User level

All

Required products

  • Flex Builder 3 (Download trial)

Sample files

  • sap_ri_pt2_starter.zip (23 KB)
  • sap_ri_pt2_solution.zip (26 KB)

Additional Requirements

Sample files:

Note: The ZIP files are Flex Builder project archives. The starter archive is the completed Part 1 project archive. The solution archive contains the completed code and assets associated with this tutorial. The latter is provided for you to compare against your own completed code.

Welcome to Part 2 of this tutorial series. In this part, you will learn how to use containers to lay out visual elements and style them using the component styles and CSS. You also learn how to embed fonts and an image. This will be the visual foundation of the application.

Note: Parts 1 through 6 focus on teaching Flex development to SAP developers. Part 7 teaches Flex developers how to create a Web Dynpro application. Parts 8 and 9 show both SAP and Flex developers how to integrate the Flex application as a Rich Island into the Web Dynpro application.

Laying out visual elements

In Part 1 you watched a video that explains the functionality of the final Web Dynpro application that you build in this tutorial series. In this part, you will lay out all of the elements of the Wagon Assembly Line application (see Figure 1).

Note: In Parts 8 and 9, when you learn how to integrate the Rich Island into the Web Dynpro application, the Flex DataGrid component pictured at the top of Figure 1 will be replaced with the Web Dynpro table UI element.

The shop floor application to display wagon inventory in colored bins
Figure 1. The shop floor application to display wagon inventory in colored bins

Figure 2 outlines the Flex framework controls and containers that you will use in this application. Note that containers (such as Application, VBox, or Canvas) hold other containers or controls and are used to lay out visual elements in an application.

The shop floor application layout in Flex components
Figure 2. The shop floor application layout in Flex components

You will learn how to style these controls and containers, which are collectively called components. Specifically, you will find that the Canvas container is useful because it not only acts as a container for layout, but can also be styled for use as a visual element, such as, for example, the blue clock or green inventory bins.

Importing a Flex Builder project

Note: If you wish to continue using the ShopFloorBins project from Part 1, skip the following steps. Otherwise, use the following steps to import the starting project archive for Part 2.

  1. In Flex Builder, right-click on the ShopFloorBins folder and select Delete.
  2. Click Yes.

    Note: In the dialog box, you may select to delete the project contents or keep them. If you keep the contents the new project will overwrite the contents.

  3. Select File > Import > Flex Project.
  4. Select Archive File and click Browse to navigate to where you downloaded sap_ri_pt2_starter.zip on your computer.
  5. Click Finish.

Creating the application layout

You will create the visual layout of the application using container controls.

  1. In the ShopFloorBins project folder, open ShopFloorBins.mxml from the src folder and locate the layout property in the opening Application tag.
  2. Change the layout property to vertical if it is not.

    A value of vertical means all the visual components you add between the Application container tags will display vertically.

  3. Inside the Application tag block, add a DataGrid control without any properties.
<mx:Application ...> <mx:DataGrid /> </mx:Application>
  1. After the DataGrid control, add a Canvas container component code block.
<mx:DataGrid /> <mx:Canvas> </mx:Canvas>
  1. To the Canvas container, add an id property with a value of assemblyLineBackground, a width property with a value of 770 and a height property with a value of 500.

    Note: A Flex framework container lays out other components, which could be other containers or controls. The Canvas container, which is just one of many Flex containers, lays out its children using absolute positioning. Absolute positioning specifies x and y layout properties relative to the upper left corner of the container, which is the 0, 0 position. The id property is the instance name for the component.

<mx:Canvas id="assemblyLineBackground" width="770" height="500" backgroundColor="#F3F3F3"> </mx:Canvas>
  1. Save the file and run it.

    You should only see the empty DataGrid control in the application. Canvas containers are not visible by default.

  1. Add the property backgroundColor with a gray color value (#F3F3F3) to the opening Canvas tag.
  1. Save the file and run it.

    Your application should appear as shown in Figure 3.

The Canvas container with a background color
Figure 3. The Canvas container with a background color
  1. Locate the Application tag and change the layout property value to horizontal.
  1. Save the file and run it.

    You will see the DataGrid control and the Canvas container aligned horizontally.

  1. Change the Application tag layout property value to absolute.
  1. Save the file and run it.

    Like a Canvas container, the Application container can be set to use absolute positioning. Because no x and y properties are specified for either the Canvas or DataGrid components, they default to the 0, 0 position of the container, which is, in this case, the Application container. When two components overlap in absolute positioning, the component that is further down in the code will be positioned above. Since the Canvas container is larger than the DataGrid control, you only see the Canvas container.

  1. Change the Application tag layout property value back to vertical.

Creating the clock layout

In this section, you create the clock layout that will show the time until the assembly line stops. You will use two Canvas containers in this display element because later in this tutorial you will apply styles to them for background color and rounded corners. Figure 4 shows the Flex components that will be used for the clock display.

The clock layout in Flex components
Figure 4. The clock layout in Flex components
  1. Between the assemblyLineBackground Canvas container tags, create another Canvas container tag set with the following properties and values:
<mx:Canvas id="assemblyLineBackground" ...> <mx:Canvas id="clockBase" width="197" height="90" y="32" x="350" horizontalCenter="0" backgroundColor="#0066FF"> </mx:Canvas> </mx:Canvas>

Note: The horizontalCenter property aligns the clockBase container to the horizontal center of its parent container, the assemblyLineBackground container.

  1. Between the clockBase Canvas tags, create a Label control and add the following properties and values to the Label control:
<mx:Label id="clockTitle" text="TIME UNTIL SHUTDOWN" width="148" y="10" horizontalCenter="0" textAlign="center"/>

Note: The textAlign property will center the text within the Label control.

  1. After the clockTitle Label control, create a Canvas container tag set and add the following properties and values to the Canvas container:
<mx:Label id="clockTitle" .../> <mx:Canvas id="timeLeftBackground" y="35" right="10" left="10" backgroundColor="#000000"> </mx:Canvas>
  1. Between the timeLeftBackground Canvas tags, create a Label control and add the following properties and values to the Label control:
<mx:Canvas id="timeLeftBackground"...> <mx:Label id="timeLeft" text="00" textAlign="center" verticalCenter="0" horizontalCenter="0"/> </mx:Canvas>

Note: The verticalCenter property aligns the Label control to the vertical center of the parent Canvas container.

  1. Save the file and run it.

Your application should appear as shown in Figure 5.

The application with the clock layout in the Canvas container
Figure 5. The application with the clock layout in the Canvas container

You can see that the timeLeft Label control text is not visible against the background of the timeLeftBackground Canvas container. This will change once you apply the styles later in this tutorial.

Creating the bin layout

In this section, you create the colored bins that will display available inventory for each wagon part. For each bin you will use a VBox container that encompasses a Label control and a Canvas container. The Canvas container, in turn, holds a TextInput control and is the element that has the green background color. Figure 6 shows the Flex components that will be used for the bin display.

The bin layout in Flex components; the X represents a unique number for each bin.
Figure 6. The bin layout in Flex components; the X represents a unique number for each bin.
  1. After the closing clockBase Canvas tag, but still inside the assemblyLineBackground Canvas container tags, create a VBox container tag set and add a x property with a value of 47 and a y property with a value of 178.
  2. Within the opening VBox container tag, add the backgroundColor property with a value of #0066FF.
<mx:VBox x="47" y="178" backgroundColor="#0066FF"> </mx:VBox>
  1. Between the VBox tag set, add a Label control with the id property set to binTitle0. Flex is a zero-indexed programming language, so you will start numbering at zero. This is merely a convention and is not required.
  2. Also add the text property with a value of Bin, a textAlign property with a value of center and a width property with a value of 100.

    Note: The text value is what will be displayed to the user.

<mx:VBox ...> <mx:Label id="binTitle0" text="Bin" textAlign="center" width="100"/> </mx:VBox>
  1. After the binTitle0 Label control, add a Canvas container tag set and add the following properties and values to the Canvas tag:
<mx:Label id="binTitle0" . . ./> <mx:Canvas id="binCanvas0" width="100" height="100"> </mx:Canvas>
  1. Between the binCanvas0 Canvas tags, add a TextInput control and add the following properties and values to the TextInput tag:
<mx:Canvas id="binCanvas0" ...> <mx:TextInput id="binData0" text="amount" editable="false" width="60" height="30" horizontalCenter="0" verticalCenter="0" textAlign="center"/> </mx:Canvas>
  1. Save the file and run it.

    Your application should appear as shown in Figure 7.

Your application with one bin laid out
Figure 7. Your application with one bin laid out

Add additional bins

In this section, you will create the other four bins needed for the wagon inventory.

  1. Copy the entire VBox tag block and paste it four times after the first VBox tag set, but still between the assemblyLineBackground Canvas tags.
  2. For the second VBox tag block, change its x property to 186.
  3. Locate the id property of the new Label control and change its value to binTitle1.
  4. Locate the id property of the new Canvas container and change its value to binCanvas1.
  5. Locate the id property of the new TextInput control and change its value to binData1.
<mx:VBox x="186" y="178" backgroundColor="#0066FF"> <mx:Label id="binTitle1" text="Bin" textAlign="center" width="100"/> <mx:Canvas id="binCanvas1" width="100" height="100"> <mx:TextInput id="binData1" text="amount" editable="false" width="60" height="30" horizontalCenter="0" verticalCenter="0" textAlign="center"/> </mx:Canvas> </mx:VBox>
  1. For the third VBox tag block, change the x property value to 331 and increment the id property values to binTitle2, binCanvas2 and binData2.
  2. To the fourth VBox container block, change the x property value to 471 and change the id property values to binTitle3, binCanvas3 and binData3.
  3. To the fifth new VBox container block, change the x property value to 614 and change the id property values to binTitle4, binCanvas4 and binData4.
  4. Save the file and run it.

    Your application should appear as shown in Figure 8.

The application with the additional bins
Figure 8. The application with the additional bins

Styling the visual elements

In this section you will use the component styles to change the display of the element.

  1. Locate the opening Application tag and add the backgroundGradientColors property with a value of [0xFFFFFF, 0xFFFFFF]. By default, Flex applications have a gray gradient background. With this code you are setting the application background color to a solid white background.
  2. Save the file and run it.

    Your application should appear as shown in Figure 9. The main application background is white but the Canvas container for the assembly line is gray.

The application background changed to white.
Figure 9. The application background changed to white.

Note: The timeLeft Label control text is not visible since the text color is the same as the background color.

  1. Locate the assemblyLineBackground Canvas container and add the following styles and values to the Canvas tag:
<mx:Canvas id="assemblyLineBackground" width="770" height="500" backgroundColor="#F3F3F3" borderStyle="solid" borderThickness="1" cornerRadius="10">
  1. Save the file and run it.

    Your application should appear as shown in Figure 10.

The application with a styled Canvas container
Figure 10. The application with a styled Canvas container

The next step corrects the text background in the clock.

  1. Locate the clockTitle Label and add the fontSize style with a value of 12, the fontWeight style with a value of bold and color style with a value of #FFFFFF.
<mx:Label id="clockTitle" text="TIME UNTIL SHUTDOWN" width="148" y="10" horizontalCenter="0" textAlign="center" color="#FFFFFF" fontSize="12" fontWeight="bold"/>
  1. Locate the timeLeftBackground Canvas container and add the following styles and values to the Canvas tag:
<mx:Canvas id="timeLeftBackground" y="35" right="10" left="10" backgroundColor="#000000" cornerRadius="6" backgroundAlpha=".6" borderStyle="solid" borderThickness="1">
  1. Locate the timeLeft Label control and add the color property with a value of #FFFF00.
<mx:Label id="timeLeft" text="00" textAlign="center" verticalCenter="0" horizontalCenter="0" color="#FFFF00" />
  1. Locate the binData0 TextInput control and add the fontSize style with a value of 18.
  2. Add the fontSize style to binData1, binData2, binData3 and binData4.
  3. Save the file and run it.

    Your application should appear as shown in Figure 11.

The application with styles applied
Figure 11. The application with styles applied

Creating and using a CSS file

In this section, you create a cascading style sheet (CSS) file and apply it to style the application further. You also use embedded fonts.

Create the CSS file

  1. Right-click on the assets folder in the src folder and select New > CSS File.
  2. Name the file ShopFloor.
  3. Click Finish.

    The file will be opened in Flex Builder Source mode.

  4. In the ShopFloor.css file, create a class selector named .binStyle using the curly brace notation.
  5. Between the braces, add the following attributes and values:

    Note: In a CSS file, you can use either the camel case or dash format for CSS attribute names.

.binStyle{ background-color: #339933; corner-radius: 6; border-style: solid; border-color:#000000; border-thickness: 2; drop-shadow-color: #000000; drop-shadow-enabled: true; }
  1. Create another class selector named .clockStyle using curly brace syntax.
  2. Add the following attributes and values:
.clockStyle { background-color: #44A7D4; drop-shadow-enabled: true; drop-shadow-color: #000000; corner-radius: 6; border-color: #000000; border-style: solid; border-thickness: 1; }
  1. Save the file and return to ShopFloorBins.mxml.
  2. Create a Style tag after the beginning Application tag.
  3. Add a source property with a value of assets/ShopFloor.css.
<mx:Style source="assets/shopFloor.css"/>
  1. Locate the opening VBox container tags and delete the backgroundColor property. (You'll have to delete five isntances of this property).
  2. Locate the binCanvas0 Canvas and add a styleName property with the value of binStyle.
<mx:Canvas id="binCanvas0" width="100" height="100" styleName="binStyle">
  1. Add the styleName property and value to binCanvas1, binCanvas2, binCanvas3 and binCanvas4.
  2. Locate the clockBase Canvas container and delete the backgroundColor property.
  3. Add the styleName property with a value of .clockStyle.
<mx:Canvas id="clockBase" width="197" height="90" y="32" x="350" horizontalCenter="0" styleName="clockStyle">
  1. Save the file and run it.

    Your application should appear as shown in Figure 12.

The application with styles applied to the Canvas containers
Figure 12. The application with styles applied to the Canvas containers

Creating and using embedded fonts

In this section, you will embed three fonts. Fonts are normally embedded when there is a good chance the font will not be on the end user's computer. Fonts are copyrighted so you will need to purchase a license in order to use most fonts.

  1. Return to ShopFloor.css.
  2. After the .clockStyle selector, embed a font using the @font-face syntax and curly braces.
  3. Within the curly braces add an attribute named src with a value of local("Arial"), the fontFamily attribute with a value of fontArialBold and the font-weight attribute with a value of bold.
@font-face { src: local("Arial"); fontFamily:"fontArialBold"; font-weight: bold; }
  1. Embed another font using @font-face syntax.
  2. Add the src attribute with a value of local("Arial")and the fontFamily attribute with a value of fontArialRegular.
@font-face { src: local("Arial"); fontFamily:"fontArialRegular"; }
  1. Embed another font using @font-face syntax.
  2. Add the src attribute with a value of local("Times New Roman")and the fontFamily attribute with a value of fontTimes.
@font-face { src: local("Times New Roman"); fontFamily: "fontTimes"; }
  1. After the embedded font code, create a class selector named .binInputFont using curly brace syntax.
  2. Add the following attributes and values:
.binInputFont { fontFamily: fontArialBold; fontSize: 24pt; color: #000000; font-weight:bold; }
  1. Create another class selector named .titleFont using curly brace syntax.
  2. Add the following attributes and values:
.titleFont { fontFamily: fontArialBold; fontSize: 16pt; color: #000000; font-weight:bold; }
  1. Create another class selector named .clockFont using curly brace syntax.
  2. Add the following attributes and values:
.clockFont { fontFamily: fontTimes; fontSize: 30pt; }
  1. Save the file.
  2. Return to ShopFloorBins.mxml.
  3. Locate the binTitle0 Label control.
  4. Add the styleName property with a value of titleFont.
  5. Add the same styleName property and value to binTitle1, binTitle2, binTitle3 and binTitle4.
  6. Locate the binData0 TextInput control.
  7. Add the styleName property with a value of binInputFont.
  8. Add the styleName property and value to binData1, binData2, binData3 and binData4.
  9. Locate the clockTitle Label control.
  10. Add the styleName property with the value titleFont.
  11. Locate the timeLeft Label control and add the styleName property with a value of clockFont.
  12. Save the file and run it.

    Your application should appear as shown in Figure 13.

The application layout using CSS
Figure 13. The application layout using CSS

Embedding an image

In this section, you use the @Embed syntax within the Image control to embed an image. By embedding, the image is compiled into the SWF file and allows faster access than if it is loaded at runtime.

  1. Before the closing assemblyLineBackground Canvas container tag, add an Image control with the following properties and values:
<mx:Image x="31" y="310" source="@Embed (source='assets/belt.swf')" width="700"/>
  1. After the Image tag, create a Label control with the following properties and values.
<mx:Label text="Wagon Assembly Line" bottom="32" horizontalCenter="0" styleName="binInputFont"/>
  1. Save the file and run it.

    Your application should appear as shown in Figure 14.

The application is now ready for data.
Figure 14. The application is now ready for data.

Where to go from here

In this tutorial you created the layout using the Application, VBox and Canvas containers and some additional controls. You styled the application with a combination of component styles and CSS. You used embedded fonts and an image to start the visual foundation of the application. If you are interested in learning more about these topics, visit the following links:

  • Using the DataGrid control and binding to data
  • Using pre-built Flex controls (4:34)
  • Working with containers (12:12)
  • Applying styles to MXML components (29:06)
  • Embedding fonts (28:59)
  • Flex 3 Style Explorer

In Part 3, SAP developers will create data for this Flex application and bind it to the controls.

Exploring Rich Island development with Flex Builder

For your reference, here are all the parts in this series:

  • SAP developers: Build an interactive Flex application from scratch
    • Part 1: Getting started
    • Part 2: Laying out and styling visual elements
    • Part 3: Handling data and binding it to controls
    • Part 4: Creating a custom component
    • Part 5: Animating with ActionScript
    • Part 6: Synchronizing data in components
  • Flex developers: Create a Web Dynpro application
    • Part 7: Creating an SAP application
  • Flex and SAP developers: Create a working Rich Island
    • Part 8: Creating a Rich Island and handling data
    • Part 9: Communicating between a Rich Island and a Web Dynpro application
 

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement