| Package | Top Level |
| Class | public final class int |
| Inheritance | int Object |
The properties of the int class are static, which means you do not need an object to use them, so you do not need to use the constructor. The methods, however, are not static, which means that you do need an object to use them. You can create an int object by using the int class constructor or by declaring a variable of type int and assigning the variable a literal value.
The int data type is useful for loop counters and other situations where a floating point number is not needed, and is similar to the int data type in Java and C++. The default value of a variable typed as int is 0
If you are working with numbers that exceed int.MAX_VALUE, consider using Number.
The following example calls the toString() method of the int class, which returns the string 1234:
var myint:int = 1234; myint.toString();
The following example assigns the value of the MIN_VALUE property to a variable declared without the use of the constructor:
var smallest:int = int.MIN_VALUE;View the examples. See also
| uint, Number |
| Property | Defined by | ||
|---|---|---|---|
| MAX_VALUE : int = 2147483647 [static]
The largest representable 32-bit signed integer, which is 2,147,483,647.
| int | ||
| MIN_VALUE : int = -2147483648 [static]
The smallest representable 32-bit signed integer, which is -2,147,483,648.
| int | ||
| Function | Defined by | ||
|---|---|---|---|
|
Constructor; creates a new int object.
| int | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
Returns the string representation of an
int object. | int | ||
|
Returns the primitive value of the specified int object.
| int | ||
public static const MAX_VALUE:int = 2147483647
trace("int.MIN_VALUE = "+int.MIN_VALUE);
trace("int.MAX_VALUE = "+int.MAX_VALUE);
This code logsdisplays the following values:
int.MIN_VALUE = -2147483648 int.MAX_VALUE = 2147483647
public static const MIN_VALUE:int = -2147483648
trace("int.MIN_VALUE = "+int.MIN_VALUE);
trace("int.MAX_VALUE = "+int.MAX_VALUE);
This code logsdisplays the following values:
int.MIN_VALUE = -2147483648
int.MAX_VALUE = 2147483647
public function int(num:Object)
int.toString() and int.valueOf(). You do not use a constructor when using the properties of a int object. The new int constructor is primarily used as a placeholder. A int object is not the same as the int() function that converts a parameter to a primitive value.
Parameters
num:Object — The numeric value of the int object being created or a value to be converted to a number. The default value is 0 if value is not provided.
|
var n1:int = new int(3.4); var n2:int = new int(-10);See also
| int.toString(), int.valueOf() |
public function toString(radix:uint):String
int object.
Parameters
radix:uint — Specifies the numeric base (from 2 to 36) to use for the number-to-string conversion. If you do not specify the radix parameter, the default value is 10.
|
String —
A string.
|
radix parameter and returns a string that contains the corresponding representation of the number 9:
var myint:int = new int(9); trace(myint.toString(2)); // output: 1001 trace(myint.toString(8)); // output: 11
The following example results in a hexadecimal value.
var r:int = new int(250); var g:int = new int(128); var b:int = new int(114); var rgb:String = "0x"+ r.toString(16)+g.toString(16)+b.toString(16); trace(rgb); // output: rgb:0xFA8072 (Hexadecimal equivalent of the color 'salmon')
public function valueOf():int
int —
An int value.
|
numSocks object.
var numSocks = new int(2); trace(numSocks.valueOf()); // output: 2
IntExample to show how
to work with and check the validity of int data types. This is accomplished using the
following steps:
a and b are declared in the constructor.addIntegers().c is assigned the outcome of parseInteger(),
which checks the validity of the string passed to it to ensure it is an integer value
in the acceptable range for int data types and returns an int equal to the integer value
of the string if it is valid.a and c are then added together using addIntegers().
package {
import flash.display.Sprite;
public class IntExample extends Sprite {
public function IntExample() {
var a:int = 512;
var b:int = -128;
trace(addIntegers(a, b)); // 384
var c:int = parseInteger("32");
trace(addIntegers(a, c)); // 544
}
public function addIntegers(a:int, b:int):int {
return a + b;
}
public function parseInteger(str:String):int {
var num:Number = parseInt(str);
if(!isNaN(num) && num <= int.MAX_VALUE && num >= int.MIN_VALUE) {
return int(num);
}
return 0;
}
}
}