Get start with Spark DateTimeFormatter in Flex 4.5 – Video中文教程

在下面的视频当中,我将会为大家介绍如何使用Spark DateTimeFormatter来创建小的应用程序。

Play Video – DateTimeFormatterDemo

这是第一次尝试以视频的模式来介绍,所以希望大家多多指点,有任何的需求可以给我留言,我们会考虑在日后添加更多类似的视频教程。

Flex 4.5中globalization相关新功能示例

随着Flex 4.5的推出,一些有关globalization(全球化)的新功能也随之出炉。考虑到开发者对程序全球化的开发需求,我们为此创建了一批与全球化相关的新功能的示例。这些示例主要涵盖以下这些类:

DateTimeFormatter

CurrencyFormatter

NumberFormatter

MatchingCollator

SortingCollator

NumberValidator

CurrencyValidator

StringTool

Sort and SortField

目前这些示例多为英语,我们正在考虑添加更多的中文示例。开发者可以通过从Adobe官网安装‘Tour De Flex’ 来获得这些示例, 安装地址为:http://www.adobe.com/cn/devnet/flex/tourdeflex/

How to format a date in locale-sensitive way

In the coming new release of Flex SDK – ‘Hero’, it provides new features on the globalization support. DateTimeFormatter is such a class can help you format a date in locale-sensitive way. In this article, I will introduce you how to create an application to format a date based on locale setting.

First, you need to install the IDE for developing a Flex application, Flash Builder or Eclipse are all good choices. Then, you can download the Flex SDK ‘Hero’ from http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK . After set up development environment, we can go ahead to build our application.

First, create a comboBox in which contains different locales for users to choose.

<s:ComboBox id=”localesCB” dataProvider=”{ new ArrayCollection([‘ar-SA’,’en-GB’,’fr-FR’,’ja-JP’,’ru-RU’,’zh-CN’])}”/>

Second, create an instance of DateTimeFormatter (which is under spark namespace) in MXML declarations, and bind its locale property with above comboBox’s selected value.

<fx:Declarations>

<s:DateTimeFormatter id=”dtf” locale=”{localesCB.selectedItem}”/>

</fx:Declarations>

Then, create a dateChooser to pick up the date to format.

<mx:DateChooser id=”dateDC”/>

At last, since the format function of DateTimeFormatter is bindable, we can bind its format result with a label. That will be:

<s:Label id=”resultL” text=”{dtf.format(dateDC.selectedDate)}”/>

DONE! That is all you need to do! Really simple, right?

Let us see what does the app looks like:

When choose en-GB as locale:

When choose zh-CN as locale:

When choose ar-SA as locale:

For more info about DateTimeFormatter, please visit: http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/spark/formatters/DateTimeFormatter.html

日本9.0级强地震

北京时间2011年3月11日 13:46, 日本本州岛附近海域发生强烈地震,地震引发海啸.

在此, 为日本震区民众祈福~~~

Hello world!

This is a begining … …