Recipe 14.5. Formatting Seconds or Milliseconds as Minutes and Seconds


Problem

You want to display seconds or milliseconds in minutes and seconds (mm:ss) format.

Solution

Use either the custom ascb.util.DateFormat.formatSeconds( ) or ascb.util.DateFormat.formatMilliseconds( ) methods.

Discussion

Many values in ActionScript are given in milliseconds or seconds. For example, sound lengths are given in milliseconds. However, in most cases, you want to format the value as minutes and seconds when displaying it to the user. You can accomplish this with a short amount of code. To further simplify things, that code has already been made into static methods of the DateFormat class.

The ascb.utils.DateFormat class has two methods that convert a number to the format mm:ss. The formatSeconds( ) method converts seconds to that format, while the formatMilliseconds( ) method converts milliseconds to that format.

See Also

Recipe 14.4




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net