2 May 2011
In this exercise you will use Flash Builder to create the application user interface for the fictitious Employee Portal: Vehicle Request Form shown in Figure 1.
In this section you will use Flash Builder Design mode to build the application user interface using Flex framework components.
Note: The Properties view is displayed by default on the right side of the Flash Builder user interface (see Figure 3).
Lastly you will add a Button control using Source mode. This allows you to avoid the label value that is created for you when you drop a control into the Form container in Design mode.
Form block and below the last FormItem container, create a new FormItem container block.<s:Form>
...
<s:FormItem label="Return Date:">
<mx:DateChooser/>
</s:FormItem>
<s:FormItem>
</s:FormItem>
</s:Form>
FormItem block, create a Button control and a label property with a value of Submit Request....
<s:FormItem>
<s:Button label="Submit Request"/>
</s:FormItem>
In this section you will run the application to view it in a browser.
You should see the application shown in Figure 12.
Note: You may have to resize your browser to see the whole application.
In this section you will use Design mode to create a CSS style from a Label control.
You should see the Styles.css file open in Flash Builder (see Figure 16). You should also see the Styles.css file in the Package Explorer view within the default package.
backgroundColor property with a value of #000000, a color property with a value of #FFFFFF, a paddingLeft property with a value of 20, and a verticalAlign property with a value of middle..titleHeader
{
backgroundColor: #000000;
color: #FFFFFF;
fontSize: 16;
fontWeight: bold;
paddingLeft: 20;
verticalAlign: middle;
}
Switch to ex1_02_starter.mxml.
Note the new layout of the Label control.
In this section you will use the Flex video components to add a video to the application.
You should see the video next to the Pickup Date field in the Form container (see Figure 20). Note that the VideoDisplay control has no playback controls.
The VideoPlayer control now has a play/pause button, a seek bar, volume controls, and a full-screen option embedded with it (see Figure 21). Also note that the video starts automatically when the application launches.
VideoPlayer control.autoPlay property to the VideoPlayer control and set its value to false.Save the file and run the application.
You should see that the video does not start when the application is launched.
In this section, you will apply a pre-made skin to the Application container using the skinClass property. You will also modify the skin background.
The AppSkin.mxml file is based on the SparkSkin class and consists of two required states (normal and disabled) and a Metadata block. You will learn more about states in later videos; for now just understand that these two are required in a skin.
The HostComponent() method located within the MetaData block is a contract between the skin and the spark.components.Application container class. This gives the AppSkin.mxml skin class access to the public properties of the Application container class and allows the file to be used as a skin for the Application container. The Rect block draws the application background, in this case, setting it to a gray color. The required Group container with an id property of contentGroup represents all of the content within the Application container.
skinClass property to the opening Application tag, assigning it a value of skins.AppSkin:<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"
minWidth="955" minHeight="600"
skinClass="skins.AppSkin">
Note: If you used the content assist tool to add the value to the skinClass property, you will see that a Script block and import statement are generated. Neither the Script block nor the import statement are needed and may be deleted from the application.
Note that the application is skinned with a grey background (see Figure 23). Also note that the Employee Portal: Vehicle Request Form Label control is not centered in the application.
x property of the Employee Portal: Vehicle Request Form Label control. The x property was automatically added to your code when you dropped the Label control onto the stage in Design mode.Save the file and run the application.
It is a subtle change, but you should see that the Label control is now centered in the application.
Note that the contentGroup Group container at the end of the file horizontally centers the application content and lays out the elements vertically:
<s:Group id="contentGroup"
top="20"
horizontalCenter="0">
</s:Group>
Note also that the Rectangle component is horizontally centered with width, height, fill, and stroke properties:
<s:Rect horizontalCenter="0" width="400" height="100%">
<s:fill>
<s:SolidColor color="#CCCCCC" />
</s:fill>
<s:stroke>
<s:SolidColorStroke color="#AAAAAA" />
</s:stroke>
</s:Rect>
Rect tag, add the radiusX property with a value of 10, the top property with a value of 20, and the bottom property with a value of 20.<s:Rect horizontalCenter="0"
top="20" bottom="20"
width="750" height="100%"
radiusX="10" >
...
fill block, change the value of the SolidColor graphic's color property to #FFFBCF:<s:fill>
<s:SolidColor color="#FFFBCF" />
</s:fill>
The background color of the skin is now light yellow, the corners are rounded, and there is some space between the tops and bottoms of the rounded rectangle and the browser window (see Figure 24).
Application tag and remove the minHeight property.Save the file and run the application.
Note that when you resize the browser, the application still does not resize appropriately.
Rect tag and notice that the height property is set to 100%. If you set this property to 100% the bottom of the rectangle resizes based on the browser, but the contentGroup does not resize with the browser.Rect tag's height property so that it is bound to the height of the contentGroup and remove the bottom property.<s:Rect horizontalCenter="0" top="20" bottom="20"
width="750" height="{contentGroup.height}"
radiusX="10">
Group tag, add a bottom property with a value of 20.<s:Group id="contentGroup"
top="20" bottom="20"
horizontalCenter="0">
Save the file and run the application.
You should see that the bottom of the application now resizes appropriately. Note that the space between the bottom of the rectangle and the bottom of the browser window stays the same when you enlarge the browser. However, when you make the browser smaller, notice that the content does not automatically center (see Figure 25).
minWidth property from the opening Application tag.Note that the application moves and resizes appropriately when you make the browser window larger or smaller.
By default, the Flex components use either the Spark or MX themes. In this section you will use the Flash Builder Theme Browser to change the application theme to a different look and feel.
The application controls are now styled using the Sky theme (see Figure 28).
In this exercise you learned how to create a Flex application and navigate Flash Builder 4.5. In the next excercise, you learn how to customize Flex components and bind them to data to create an auto-generating email address.
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.