Exercise 1.1: Setting up Flash Builder and your project files
Exercise 5.1: Using text controls
全部
In this exercise, you will use text layout properties and controls to display and format the information for the Cafeteria and Monthly Events components of the sample application (see Figure 1). You will also display text in a vertical orientation.

In this exercise, you will learn how to:
In this section, you will use Flash Builder flow elements to format the text content for the Cafeteria component of the sample application.
span tags and nested code.Note that the span and br flow tags being used within the component are based on HTML tags.
<s:span fontWeight="normal">
Water content (grams per 100g) 47.31<s:br/>
Calorie content of Food (kcals per 3.5oz) 283<s:br>
Protein content (grams per 100g) 13.25<s:br/>
Fat content (lipids) (grams per 100g) 16.18<s:br/>
Ash content (grams per 100g) 2<s:br/>
Carbohydrate content (grams per 100g) 21.26<s:br/>
Dietary Fiber content (grams per 100g) N/A<s:br/>
Sugar content (grams per 100g) N/A<s:br/>
</s:span>
span tags with a RichText control. ...
<s:RichText/>
<s:span fontWeight="normal">
Water content (grams per 100g) 47.31<s:br/>
Calorie content of Food (kcals per 3.5oz) 283<s:br/>
Protein content (grams per 100g) 13.25<s:br/>
Fat content (lipids) (grams per 100g) 16.18<s:br/>
Ash content (grams per 100g) 2<s:br/>
Carbohydrate content (grams per 100g) 21.26<s:br/>
Dietary Fiber content (grams per 100g) N/A<s:br/>
Sugar content (grams per 100g) N/A<s:br/>
</s:span>
</s:RichText>
...
You should see each food specification item on its own line (see Figure 2).

lineHeight property value to 20.<s:RichText width="100%"
lineHeight="20">
Note that there is now more space between each line of text (see Figure 3).

In this section, you will use the online Text Layout Editor demo to create label text for the sample application.



RichText tags in the Cafeteria component (see Figure 7).
Note that the flow:span tags are similar to the <s:span> tags in Flash Builder. The online text generation tool can be used to create all the HTML markup that can be used with Flash Builder components. However, the XML namespace component, flow, must be modified to make the code functional in Flash Builder.
flow:span tags and its content (see Figure 8).
RichText and span tags....
<s:RichText>
<flow:span fontFamily="Arial"
fontWeight="bold">Chicken Satay</flow:span>
<s:span fontWeight="normal">
...
You should see an error occur.

The application is producing an error because the code you copied from the HTML generator contains the flow prefix within the span tags. In order for the copied code to work, you must alter the namespace being used with the span tags.
s to map the span element to the Spark namespace.<s:span fontFamily="Arial"
fontWeight="bold">Chicken Satay</s:span>
span tag. <s:span fontFamily="Arial"
fontWeight="bold">Chicken Satay</s:span><s:br/>
You should see the Chicken Satay text displayed (see Figure 10).

<s:TextArea>
<s:span fontWeight="bold">COMPANY PICNIC
...
<s:span fontWeight="bold">FAMILY DAY AT THE BALL PARK
...
</s:TextArea>
<s:TextArea color="#0B85B7"
height="100%" width="100%"
contentBackgroundColor="#FCFCE0">
You should see the content within the MonthlyEvents component as shown in Figure 11. Note the lack of vertical spacing between the paragraph title text and content text and the fact that you can edit the text within the TextArea control. Lastly, remember that the TextArea control has a Scroller component built into it to create a scrollbar if the text content requires one.

MonthlyEvents component, to the TextArea control, assign the editable property value to false.<s:TextArea color="#0B85B7"
height="100%" width="100%"
contentBackgroundColor="#FCFCE0"
editable="false">
TextArea tags, note that the span tags containing the paragraph content are preceded by paragraph (p) tags (see Figure 12).
paragraphSpaceBefore property value to 4. The paragraphSpaceBefore property adds the defined amount of pixels before any paragraph tag.
<s:TextArea color="#0B85B7"
height="100%" width="100%"
contentBackgroundColor="#FCFCE0"
editable="false"
paragraphSpaceBefore="4">
You should see that the text is no longer editable within the TextArea control. Also note the spacing between the paragraph title and content (see Figure 13).

MonthlyEvents component in Flash Builder.TextArea block, assign the paddingTop, paddingRight, paddingBottom, and paddingLeft property values to 15.paragraphSpaceBefore="4">
<s:TextArea color="#0B85B7" height="100%" width="100%"
contentBackgroundColor="#FCFCE0"
paragraphSpaceBefore="4"
paddingBottom="15"
paddingTop="15"
paddingLeft="15"
paddingRight="15">
...
You should see there is an extra 15 pixels of space between the edge of the container and the text (see Figure 14).

In this section, you will use vertical text as a label to a set of information.
HGroup container.<s:HGroup>
<s:RichText width="100%" lineHeight="20">
...
</s:RichText>
</s:HGroup>
HGroup container, assign the verticalAlign property value to top and the width property value to 100%.<s:HGroup verticalAlign="top" width="100%">
...
HGroup container, create a Label control.</s:RichText>
<s:Label/>
</s:HGroup>
text property value to Calorie Information, the fontWeight property value to bold and the rotation property value to 270.<s:Label text="Calorie Information"
fontWeight="bold" rotation="270"/>
You should see the Calorie Information text displayed vertically on the right side of the Cafeteria Panel container and the text within the RichText control is now too long to fit on one line (see Figure 15).

RichText control and HGroup container tags to between the opening HGroup container and RichText control tags. You want the Cafeteria Information text to display on the left side of food content information. Therefore, the Label control needs to be placed before the RichText control within the HGroup container so it is processed before the RichText control.
<s:HGroup>
<s:Label text="Calorie Information"
fontWeight="bold" rotation="270"/>
<s:RichText textAlign="left"
height="222" width="100%"
paddingTop="20" lineHeight="20">
...
You should see the vertical text now displays on the left side of the container as shown in Figure 16. Note that the food content information and title are still poorly formatted.

HGroup container, create a Spark Label control.<mx:Image source="assets/app_chixSatay.jpg"/>
<s:Label/>
<s:HGroup verticalAlign="top" width="100%">
text property value to Chicken Satay and the fontWeight property value to bold.<s:Label text="Chicken Satay" fontWeight="bold"/>
RichText tags, remove the span tags that contain the Chicken Satay text. RichText tags, surround each line of food content information with span tags. Place the closing span tag for each line before the number amount of each ingredient, adding a colon to separate the text from the amount. Leave the fontStyle property within the first tag.<s:RichText width="100%" lineHeight="20">
<s:span fontStyle="normal">Water content (grams per 100g)</s:span>: 47.31<s:br/>
<s:span>Calorie content of Food (kcals per 3.5oz)</s:span>: 283<s:br/>
<s:span>Protein content (grams per 100g)</s:span>: 13.25<s:br/>
<s:span>Fat content (lipids) (grams per 100g)</s:span>: 16.18<s:br/>
<s:span>Ash content (grams per 100g)</s:span>: 2<s:br/>
<s:span>Carbohydrate content (grams per 100g)</s:span>: 21.26<s:br/>
<s:span>Dietary Fiber content (grams per 100g)</s:span>: N/A<s:br/>
<s:span>Sugar content (grams per 100g)</s:span>: N/A<s:br/>
</s:RichText>
span tag the fontStyle property value of italic.<s:RichText width="100%" lineHeight="20">
<s:span fontStyle="italic">Water content (grams per 100g)</s:span>: 47.31<s:br/>
<s:span fontStyle="italic">Calorie content of Food (kcals per 3.5oz)</s:span>: 283<s:br/>
<s:span fontStyle="italic">Protein content (grams per 100g)</s:span>: 13.25<s:br/>
<s:span fontStyle="italic">Fat content (lipids) (grams per 100g)</s:span>: 16.18<s:br/>
<s:span fontStyle="italic">Ash content (grams per 100g)</s:span>: 2<s:br/>
<s:span fontStyle="italic">Carbohydrate content (grams per 100g)</s:span>: 21.26<s:br/>
<s:span fontStyle="italic">Dietary Fiber content (grams per 100g)</s:span>: N/A<s:br/>
<s:span fontStyle="italic">Sugar content (grams per 100g)</s:span>: N/A<s:br/>
</s:RichText>
You should see the text within the span tags are italic, but the amounts are not (see Figure 17).

HGroup container and add a height property set to 200.You should see that the Panel submit buttons are aligned (see Figure 18).

You can use lineHeight to define the space between multiple lines of text.
You can use the rotation property to change the text orientation.
The TextArea component has a built-in Scroller component, and doesn't need a separate scroller defined for it.