Chapter 7. Numbers, Math, and Dates

FEATURED CLASSES

  • Number

  • int

  • uint

  • Math

  • Date

Without good support for numbers, there's not much you can program. It should be no surprise, then, that ActionScript 3.0 enables all kinds of numeric activity, from basic arithmetic to date and time handling. With the information in this chapter, you can start making useful, interactive, and aesthetic computations.

Understanding Numeric Types

Using ActionScript, you can create numbers of different types. To understand how to use these, however, you must take a step back and look at the sets of numbers themselves and what they represent. Later, you will review how different kinds of numbers are represented on modern computers. Knowing the implications of these implementation details can help the wary programmer understand which data types are appropriate in which situations, the limitations of the language, and common problems that might arise. If you're familiar with numeric types in other languages, you might want to skip ahead to "Using Numbers in ActionScript."

Sets of Numbers

A number is a number is a number, right? Not so; there are several types of numbers. These types of numbers are defined by the set of values that they can represent.

Most familiar might be the set of natural numbers, or N. This set contains whole numbers starting with zero: {0, 1, 2, 3, ...}. These are the numbers you use to count discrete objects: "I have two parents." "There are four emergency exits on this aircraft." "This piano has ...

Get ActionScript 3.0 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.