Number Class | Flash 5 |
wrapper class for primitive numeric data |
new Number(value)
An expression to be resolved and, if necessary, converted to a numeric value, then wrapped in a Number object.
The following properties are accessed directly as properties of the Number class, using Number.propertyName. To access them you do not need to instantiate a new Number object (i.e., there is no need for the constructor function). Some of these properties, such as NaN, don't even require the Number.propertyName notation. You can simply use NaN as shorthand for Number.NaN (details follow in entries for each property).
The largest representable positive number in ActionScript.
The smallest representable positive number in ActionScript.
Special Not-a-Number value indicating invalid numeric data.
Any number more negative than -MAX_VALUE.
Any number larger than MAX_VALUE.
Convert a number to a string.
The Number class has two purposes:
It gives us access to built-in properties that represent special numeric values�MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, and POSITIVE_INFINITY�that can be used to check whether numeric data is valid or within the acceptable range.
It can be used to convert between different number systems, such as base-10 (decimal) and base-16 (hexadecimal). Refer to the Number.toString( ) method for details.
There is no need to create a Number object if you simply want to access the numeric properties it defines. In fact, where applicable, it is easier to use global property equivalents (NaN, Infinity, and -Infinity). Frankly, it is rare that you'll need the Number class properties at all.
On the other hand, the Number class's toString( ) method is used with a Number object. However, the interpreter takes care of creating a Number instance for us whenever we invoke a method on a primitive numeric value. For example, here we use toString( ) to convert a decimal number to its hexadecimal equivalent:
x = 102; hex = x.toString(16); // A Number instance is automatically and (temporarily) // created to "wrap" x for the sake of this operation.
As this is a fairly rare task, you probably won't be using instances of the Number class much.
The Math object; "Section 4.1