13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Internationalizing applications<br />

File Description<br />

com/example/program<br />

mingas3/stockticker/Fi<br />

nancialGraph.as<br />

com/example/program<br />

mingas3/stockticker/Lo<br />

calizer.as<br />

com/example/program<br />

mingas3/stockticker/St<br />

ockDataModel.as<br />

Understanding the user interface and sample data<br />

The application’s main user interface elem<strong>en</strong>ts are:<br />

a combo box for selecting a Locale<br />

a combo box for selecting a Market<br />

a DataGrid that displays data for six companies in each market<br />

a chart that shows simulated historical data for the selected company’s stock<br />

The application stores all of its sample data about locales, markets, and company stocks in the StockDataModel class.<br />

A real application would retrieve data from a server and th<strong>en</strong> store it in a class like StockDataModel. In this example,<br />

all the data is hard coded in the StockDataModel class.<br />

Note: The data displayed in the financial chart doesn’t necessarily match the data shown in the DataGrid control. The<br />

chart is randomly redrawn each time a differ<strong>en</strong>t company is selected. It is for illustration purposes only.<br />

Setting the locale<br />

After some initial setup work, the application calls the method Localizer.setLocale() to create formatter objects for the<br />

default locale. The setLocale() method is also called each time the user selects a new value from the Locale combo box.<br />

public function setLocale(newLocale:String):void<br />

{<br />

locale = new LocaleID(newLocale);<br />

}<br />

An ActionScript class that draws a chart of simulated stock data.<br />

An ActionScript class that manages the locale and curr<strong>en</strong>cy and handles the localized formatting of numbers,<br />

curr<strong>en</strong>cy amounts, and dates.<br />

An ActionScript class that holds all the sample data for the Global Stock Ticker example.<br />

nf = new NumberFormatter(locale.name);<br />

traceError(nf.lastOperationStatus, "NumberFormatter", nf.actualLocaleIDName);<br />

cf = new Curr<strong>en</strong>cyFormatter(locale.name);<br />

traceError(cf.lastOperationStatus, "Curr<strong>en</strong>cyFormatter", cf.actualLocaleIDName);<br />

symbolIsSafe = cf.formattingWithCurr<strong>en</strong>cySymbolIsSafe(curr<strong>en</strong>tCurr<strong>en</strong>cy);<br />

cf.setCurr<strong>en</strong>cy(curr<strong>en</strong>tCurr<strong>en</strong>cy, curr<strong>en</strong>tSymbol);<br />

cf.fractionalDigits = curr<strong>en</strong>tFraction;<br />

df = new DateTimeFormatter(locale.name, DateTimeStyle.LONG, DateTimeStyle.SHORT);<br />

traceError(df.lastOperationStatus, "DateTimeFormatter", df.actualLocaleIDName);<br />

monthNames = df.getMonthNames(DateTimeNameStyle.LONG_ABBREVIATION);<br />

public function traceError(status:String, serviceName:String, localeID:String) :void<br />

{<br />

if(status != LastOperationStatus.NO_ERROR)<br />

{<br />

Last updated 6/6/2012<br />

952

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!