Adobe
产品

首选目的地

  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst

教育

  • 适用于学生
  • 适用于中小学
  • 适用于高等教育机构

设计和照片

  • Photoshop
  • Illustrator
  • InDesign
  • Lightroom
  • Elements 系列

视频

  • Adobe Premiere
  • After Effects

Web 开发和 HTML5

  • Dreamweaver
  • 游戏 [在新窗口中打开]
  • 移动应用程序

Adobe Marketing Cloud

  • 什么是 Adobe Marketing Cloud?
  • 数字分析
  • Web 体验管理
  • 测试和目标定位

分析

  • SiteCatalyst
  • Adobe Discover
  • Insight

Experience Manager

  • CQ

目标

  • Test&Target
  • Recommendations
  • Search&Promote

媒体优化工具

  • AudienceManager
  • AudienceResearch

文档服务

  • Acrobat
  • SendNow [在新窗口中打开]

出版

  • Digital Publishing Suite

  • 查看所有产品
业务解决方案

按业务需求分

  • 数字分析
  • 数字出版
  • 文档管理
  • 测试和目标定位
  • 视频编缉和服务
  • Web 开发 [在新窗口中打开]
  • Web 体验管理
  • 查看所有业务需求

按行业分

  • 广播
  • 教育
  • 金融服务业
  • 政府部门
  • 出版
  • 零售业
  • 查看所有行业
支持和培训

我需要帮助

  • 产品
  • Adobe Marketing Cloud
  • 论坛 [在新窗口打开]

我想学习

  • 培训和教程
  • 证书 [在新窗口打开]
  • Adobe 开发人员连接
  • Adobe 设计中心
  • Adobe TV [在新窗口打开]
  • Adobe 市场营销中心
  • Adobe Labs [在新窗口中打开]
下载
  • 产品试用
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • 查看所有下载
公司
  • Adobe 工作机会
  • 投资者关系
  • 新闻中心
  • 隐私
  • 公司社会责任
  • 客户展示
  • 联系我们
  • 更多公司信息
购买
  • 在线商店
  • 针对学生、教师和职员
  • 批量许可
  • 优惠酬宾
  • 寻找经销商
  • Adobe Marketing Cloud 销售 [在新窗口中打开]
搜索
 
信息 登录
为何登录?登录后可以管理您的帐户,访问试用版下载、产品扩展和社区区域等。
欢迎,
我的 Adobe
我的信息
我的首选项
注销
隐私权 我的 Adobe
Adobe
产品 分类 购买   搜索  
解决方案 公司
帮助 培训
登录 注销 隐私权 我的 Adobe
Date Date
Qty:
Subtotal
Promotions
Estimated Shipping
VAT
Calculated at checkout
Total
Checkout
Adobe 开发者中心 / Flex 开发人员中心 / Flex in a Week /

Exercise 5.2: Using text layout features

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Created

5 April 2010

页面工具

在 LinkedIn 上共享
书签
打印

Tags

要求

必备知识

Exercise 1.1: Setting up Flash Builder and your project files

Exercise 5.1: Using text controls

用户级别

全部

必需产品

  • Flex Builder (Download trial)

范例文件

  • ex5_02_starter.zip (40 KB)
  • ex5_02_solution.zip (41 KB)

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.

Preview the application.
Figure 1. Review your task for this exercise.

In this exercise, you will learn how to:

  • Format text with flow elements
  • Use the online Text Layout Editor
  • Use text layout properties

Format text with flow elements

In this section, you will use Flash Builder flow elements to format the text content for the Cafeteria component of the sample application.

  1. Download the ex5_02_starter.zip file if you haven't already and extract the file ex5_02_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex5_02_starter.fxp file.
  4. Within the Package Explorer view, from the components package, open the Cafeteria.mxml file and switch to Source mode.
  5. Below the Image control, uncomment the 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>
  1. Surround the 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> ...
  1. Save the file and open the main ex5_02_starter.mxml application file.
  2. Run the application to see a baseline for what the Cafeteria content looks like.
  3. Close the browser and return to Flash Builder and the Cafeteria.mxml file.
  4. Save the file.
  5. Run the application.

    You should see each food specification item on its own line (see Figure 2).

Run the application to see the text displayed.
Figure 2. Run the application to see the text displayed.
  1. Return to the Cafeteria component in Flash Builder.
  2. To the opening tag of the RichText control, assign the lineHeight property value to 20.
<s:RichText width="100%" lineHeight="20">
  1. Save the file and run the application.
  2. Note that there is now more space between each line of text (see Figure 3).

Use the lineHeight property to space the text.
Figure 3. Use the lineHeight property to space the text.

Use the online Text Layout Editor

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

  1. Open a browser and navigate to the URL: http://labs.adobe.com/technologies/textlayout/demos/.
  2. Type Chicken Satay in the editor window (see Figure 4).
Type Chicken Satay in the editor window.
Figure 4. Type Chicken Satay in the editor window.
  1. Select the text, then, using the Character menu, change the Font to Arial and bold the text (see Figure 4).
Bold the text and change the font to Arial.
Figure 5. Bold the text and change the font to Arial.
  1. Click the Markup button (see Figure 6).
Click the Markup button.
Figure 6. Click the Markup button.
  1. Compare the generated code with the code nested between the RichText tags in the Cafeteria component (see Figure 7).
The online generated code vs. the Flash Builder code.
Figure 7. The online generated code vs. the Flash Builder code.

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.

  1. From the online code preview window, select and copy the flow:span tags and its content (see Figure 8).
Copy the flow:span tags
Figure 8. Copy the flow:span tags.
  1. Return to the Cafeteria.mxml file in Flash Builder.
  2. Paste the copied code between the opening RichText and span tags.
... <s:RichText> <flow:span fontFamily="Arial" fontWeight="bold">Chicken Satay</flow:span> <s:span fontWeight="normal"> ...
  1. Save the file.

    You should see an error occur.

  2. Open the Problems view and expand the Errors directory (see Figure 9).
Open the Problems view to see the error report.
Figure 9. Open the Problems view to see the error report.

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.

  1. Change the flow namespace to an s to map the span element to the Spark namespace.
<s:span fontFamily="Arial" fontWeight="bold">Chicken Satay</s:span>
  1. Add a line break tag after the closing span tag.
<s:span fontFamily="Arial" fontWeight="bold">Chicken Satay</s:span><s:br/>
  1. Save the file and run the application.

    You should see the Chicken Satay text displayed (see Figure 10).

Run the application to see the Chicken Satay text.
Figure 10. Run the application to see the Chicken Satay text.

Use text layout properties

In this section you will use multiple properties to configure the layout of the Monthly Events Panel container.

  1. From the Package Explorer view, open the MonthlyEvents.mxml file.
  2. Uncomment and surround the span element code with a TextArea control.
<s:TextArea> <s:span fontWeight="bold">COMPANY PICNIC ... <s:span fontWeight="bold">FAMILY DAY AT THE BALL PARK ... </s:TextArea>
  1. To the TextArea control, assign the following property values:
<s:TextArea color="#0B85B7" height="100%" width="100%" contentBackgroundColor="#FCFCE0">
  1. Save the file and run the application.

    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.

Run the application to see the text can be edited and to see the spacing between title and content text.
Figure 11. Run the application to see the text can be edited and to see the spacing between title and content text.
  1. Return to Flash Builder.
  2. In the 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">
  1. Between the TextArea tags, note that the span tags containing the paragraph content are preceded by paragraph (p) tags (see Figure 12).
Notice the paragraph tags.
Figure 12. Notice the paragraph tags.
  1. To the TextArea control, assign the 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">
  1. Save the file and run the application.
  2. Try and edit the text within the TextArea control.

    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).

Note the space between the text and the
Figure 13. Note the space between the text and the
  1. Return to the MonthlyEvents component in Flash Builder.
  2. To the 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"> ...
  1. Save the file and run the application.

    You should see there is an extra 15 pixels of space between the edge of the container and the text (see Figure 14).

Note the space that is now between the top, bottom, left, and right of the text in the Monthly Events panel.
Figure 14. Note the space that is now between the top, bottom, left, and right of the text in the Monthly Events panel.

Display vertical text

In this section, you will use vertical text as a label to a set of information.

  1. Return to Flash Builder.
  2. Open the Cafeteria.mxml file.
  3. Surround the RichText control and its contents with an HGroup container.
<s:HGroup> <s:RichText width="100%" lineHeight="20"> ... </s:RichText> </s:HGroup>
  1. To the HGroup container, assign the verticalAlign property value to top and the width property value to 100%.
<s:HGroup verticalAlign="top" width="100%"> ...
  1. Between the closing tag of the RichText control and the closing tag of the HGroup container, create a Label control.
</s:RichText> <s:Label/> </s:HGroup>
  1. To the Label control, assign the 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"/>
  1. Save the file and run the application.

    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).

See the vertical text is on the right side of the container.
Figure 15. See the vertical text is on the right side of the container.
  1. Return to Flash Builder.
  2. Within the Cafeteria.mxml file, move the Label control from between the closing 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"> ...
  1. Save the file and run the application.

    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.

See the vertical text is now on the left of the food content information.
Figure 16. See the vertical text is now on the left of the food content information.
  1. Return to the Cafeteria.mxml file in Flash Builder.
  2. Between the Image control and the HGroup container, create a Spark Label control.
<mx:Image source="assets/app_chixSatay.jpg"/> <s:Label/> <s:HGroup verticalAlign="top" width="100%">
  1. To the Label control, assign the text property value to Chicken Satay and the fontWeight property value to bold.
<s:Label text="Chicken Satay" fontWeight="bold"/>
  1. From within the RichText tags, remove the span tags that contain the Chicken Satay text.
  2. Within the 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>
  1. Assign each 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>
  1. Save the file and run the application.

    You should see the text within the span tags are italic, but the amounts are not (see Figure 17).

 See the text within the span tags is italic, the amounts are not and the Chicken Satay label is now centered above the food content information
Figure 17. See the text within the span tags is italic, the amounts are not and the Chicken Satay label is now centered above the food content information
  1. Return to Flash Builder and Cafeteria.mxml.
  2. Locate the HGroup container and add a height property set to 200.
  3. Save the file and run the application.

    You should see that the Panel submit buttons are aligned (see Figure 18).

See that the Panel buttons are aligned.
Figure 18. See that the Panel buttons are aligned.

Test your knowledge

Which property lets you modify the space between each line of text?

You can use lineHeight to define the space between multiple lines of text.

Which property can be used to change the orientation of text to vertical?

You can use the rotation property to change the text orientation.

What do you need to do to get scrollbars in a TextArea component?

The TextArea component has a built-in Scroller component, and doesn't need a separate scroller defined for it.

产品

  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements 系列
  • SiteCatalyst

下载

  • 产品试用
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

支持和培训

  • 产品帮助
  • 论坛

购买

  • 在线商店
  • 针对学生、教师和职员
  • 批量许可
  • 优惠酬宾
  • 寻找经销商

公司

  • 新闻中心
  • 合作伙伴计划
  • 公司社会责任
  • 工作机会
  • 投资者关系
  • 事件
  • 法律
  • 安全性
  • 联系 Adobe
选择您的地区 中国(更改)
选择您的地区 关闭

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 © 2013 Adobe Systems Software Ireland Ltd. All rights reserved.

使用条款 | 隐私权 | Cookies

京 ICP 备 10217899 号 京公网安备 110105010404