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 / Flex Developer Center /

Layout mirroring with Flex

by 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

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
controls Flex localization MXML Spark text

Requirements

Prerequisite knowledge

Familiarity with ActionScript and MXML is required.

User level

Intermediate

Required products

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

Sample files

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

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

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:

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

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

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

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

  • Increasing Flex and ActionScript development productivity with Flash Builder 4.5 and SourceMate 3.0
  • Developer productivity improvements in Flash Builder 4
  • Creating ColdFusion Master/Detail forms with Adobe Flash Builder 4
  • AdvancED Flex 3 excerpt: Sculpting interactive business intelligence interfaces
  • Creating components and enforcing separation of concerns with Flex
  • Creating Flex components
  • A brief overview of the Spark architecture and component set
  • Introducing Adobe Flex 4.5 SDK
  • Using Flash Builder 4 to create Spark item renderers
  • Tips for using Flex containers

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex User Forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

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