Adobe
产品
Acrobat
Creative Cloud
创意套装
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
更多产品
解决方案
数字营销
数字媒体
教育
金融服务业
政府部门
网页体验管理
更多解决方案
学习帮助下载公司
商店
在线商店
批量许可
查找经销商
搜索
 
信息 登录
欢迎,我的支持
我的帐户
注销
为何登录?登录后可以管理您的帐户,访问试用版下载、产品扩展和社区区域等。
Adobe
产品 分类 购买   搜索  
解決方案 公司
学习
登录 注销 我的货物 我的支持
Date Date
Qty:
Subtotal
Checkout
Adobe 开发者中心 / Flex 开发人员中心 /

Layout mirroring with Flex

作者 Michaël Chaize

Michaël Chaize
  • Adobe

Content

  • Three mirroring examples
  • Implementing mirroring
  • Tips for using layout mirroring
  • Where to go from here

Created

17 January 2011

页面工具

在 Facebook 上共享
在 Twitter 上共享
在 LinkedIn 上共享
书签
打印

Tags

要求

必备知识

Familiarity with ActionScript and MXML is required.

用户级别

中级

必需产品

  • Flash Builder 4 (Download trial)
  • Flex 4.1 SDK

范例文件

  • flex-layout-mirroring.zip

When Adobe officially launched Flex 4.1 many developers were excited by a major new feature: layout mirroring. Some countries use right-to-left languages such as Arabic or Hebrew, which means that many Flex developers need to support right-to-left (RTL) locales. What you may not realize about RTL is that it targets not only text fields, but the whole user interface. Acrobat 8, for example, was localized in Arabic by Winsoft. Within the application, the entire UI is mirrored, including menus, lists, combo-boxes, and labels (see Figure 1). The vertical scroll bars appear on the left instead of the right, and with horizontal scrollbars, the thumb starts on the right side of the control instead of the left.

Adobe Acrobat Professional localized in Arabic.
Figure 1. Adobe Acrobat Professional localized in Arabic.

To support layout mirroring, new APIs have been added including the layoutDirection style property, which supports layout mirroring and the direction style property, which controls text direction in text controls. To change your application's layout from left-to-right (LTR) to RTL, simply set the layoutDirection property to "rtl" . It's the easiest way to work with RTL interfaces. This new property can also be set on any UIComponent, GraphicElement, SpriteVisualElement, or UIMovieClip object. This new API works with MX and Spark components.

For text in text components, you'll need to use the Flash Text Engine (FTE) introduced in Flash Player 10. Set the direction property to "rtl" on text components to reverse the default direction.

Three mirroring examples

I developed some samples for Tour de Flex to illustrate these new capabilities. To access these samples, download and install the Tour de Flex application, and explore Flex 4 > Coding Techniques > Layout Mirroring.

The first sample lets you play with the two new properties: layoutDirection for layout controls, and direction for text controls. Even advanced components, such as charting controls, are supported. If you try out the sample, you'll notice that the characters themselves are not rendered from right to left. This is because they use an LTR-based character set.

Note: The samples modify the layout of the panel in, not the Application tag.

缺少 Flash player 您必须装有 Flash 10? 您必须装有 Flash 10?

The second sample demonstrates how the new mirroring API works with all coordinates. To see this in action, draw something in the panel below and toggle the layout direction; your drawing will be mirrored:

缺少 Flash player 您必须装有 Flash 10? 您必须装有 Flash 10?

The third sample illustrates mirroring text in a text input control:

缺少 Flash player 您必须装有 Flash 10? 您必须装有 Flash 10?

Implementing mirroring

As you can see in the examples above, the two new direction properties in Flex 4.1 make it easy to modify the direction of your application's layout controls, text controls, or both. The layoutDirection property deals strictly with layout mirroring, or how the containers and controls are drawn on the screen. By default, this property is set to "ltr" (left to right), but you can change this value at runtime to "rtl" (right to left). The easiest way is to set this property at the Application level (in the MXML Application tag) because all the containers and controls will inherit its value. You can use either MXML or ActionScript to set this property.

For example, in MXML, you can use the following:

<s:MyContainer id="myContainer" layoutDirection="rtl"/>

Alternatively, you can use setStyle() in ActionScript:

myContainer.setStyle("layoutDirection", "rtl");

You can also use CSS to set the layoutDirection property on your components:

s|Panel { layoutDirection: rtl; }

The direction property controls the direction in which text is rendered in text-based controls. Typically, you'd use the direction property on the Application tag or the parent container of your text controls. Remember that the direction style is built into Spark text components, because those text controls use the new Flash Text Engine. To use this text engine with MX controls you'll need to adjust your compiler settings; for example:

mxmlc -theme+=themes/MXFTEText.css MyApp.mxml

When you use the theme compiler option to specify the MXFTEText.css theme file, the compiler replaces mx.core.UITextField components with mx.core.UIFTETextField components, which support FTE and layout mirroring on text.

Tips for using layout mirroring

When possible, set the layoutDirection and direction properties directly on the Application container. Avoid using absolute positioning and be careful with mirroring images. If you plan to mirror the contents of images (or videos), you should reverse your graphical assets in your image editing tool prior to importing them into your Flex application. Also, note that the Image, BitmapImage, and VideoPlayer controls don't inherit the layoutDirection property from their parent container. Lastly, be aware that in many components, navigation with the arrow keys changes depending on the direction of the text. Always test your components with the arrow keys.

Where to go from here

Now that you know how easy it is to add layout mirroring behavior to your Flex application, I encourage you to download and install Flex 4.1 and start playing with the layoutDirection and direction properties.

For more information, see Adobe Flex Layout Mirroring.


This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.

More Like This

  • Creating Flex components
  • Creating components and enforcing separation of concerns with Flex
  • AdvancED Flex 3 excerpt: Sculpting interactive business intelligence interfaces
  • Creating drawing shapes for Top Drawer with ActionScript 3.0 – Part 1
  • Creating drawing shapes for Top Drawer with ActionScript 3.0 – Part 2
  • 利用Flash Builder 4.5和SourceMate 3.0提升Flex和 ActionScript开发效率
  • Adobe Flex 4.6 SDK介绍
  • 介绍 Adobe Flex 4.5 SDK
  • 在Flash Builder 4beta中提升开发者的生产力
  • Using Flash Builder 4 to create Spark item renderers

产品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • 移动应用程序
  • Photoshop
  • Touch Apps

解决方案

  • 数字营销
  • 数字媒体
  • 网页体验管理

行业

  • 教育
  • 金融服务业
  • 政府部门

帮助

  • 产品帮助中心
  • 订货和退货
  • 下载和安装
  • 我的 Adobe

学习

  • Adobe 开发人员连接
  • Adobe TV
  • 培训和认证
  • 论坛
  • 设计中心

购买方式

  • 在线商店
  • 批量许可
  • 查找经销商

下载

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

公司

  • 新闻编辑室
  • 合作伙伴计划
  • 公司社会责任
  • 工作机会
  • 投资者关系
  • 事件
  • 法律
  • 安全
  • 联系 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 © 2012 Adobe Systems Incorporated. All rights reserved.

使用条款 | 隐私政策和 Cookies (更新)

京 ICP 备 10217899 号 京公网安备 110105010404