パッケージトップレベル
public final class int
継承int Inheritance Object

int クラスを使用すると、32 ビットの符号付き整数を表すデータ型を操作できます。int クラスで表される値の範囲は、-2,147,483,648 (-2^31) ~ 2,147,483,647 (2^31-1) です。

int クラスのプロパティは静的であるため、プロパティを使用するためのオブジェクトは不要で、コンストラクタを使用する必要はありません。ただし、メソッドは静的でないため、メソッドを使用するためのオブジェクトは不要です。int オブジェクトは、int クラスコンストラクタを使用するか、int 型の変数を宣言してその変数にリテラル値を割り当てることによって作成することができます。

int データ型は、ループカウンタおよび浮動小数の不要なその他の状況に効果的で、Java および C++ の int データ型と似ています。int 型変数のデフォルト値は 0 です。

int.MAX_VALUE を超える数値を処理する場合には、Number を使用することを検討してください。

次の例では、int クラスの toString() メソッドを呼び出します。このメソッドは、ストリング 1234 を返します。

 var myint:int = 1234;
 myint.toString();
 

次の例では、コンストラクタを使用せずに、MIN_VALUE プロパティの値を宣言された変数に割り当てます。

 var smallest:int = int.MIN_VALUE;
 

例の表示

関連項目

uint
Number
データ型の詳細
型変換


パブリックプロパティ
 プロパティ定義
 Inheritedconstructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクタ関数への参照です。
Object
 Inheritedprototype : Object
[static] クラスまたは関数オブジェクトのプロトタイプオブジェクトへの参照です。
Object
パブリック Methods
 メソッド定義
  
int(num:Object)
コンストラクタ; 新しい int オブジェクトを作成します。
int
 Inherited
指定されたプロパティがオブジェクトに定義されているかどうかを示します。
Object
 Inherited
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
Object
 Inherited
指定されたプロパティが存在し、列挙できるかどうかを示します。
Object
 Inherited
ループ処理に対するダイナミックプロパティの可用性を設定します。
Object
  
toExponential(fractionDigits:uint):String
数値のストリング表現を指数表現で返します。
int
  
toFixed(fractionDigits:uint):String
数値のストリング表現を固定小数点表現で返します。
int
  
toPrecision(precision:uint):String
数値のストリング表現を指数表現または固定小数点表現で返します。
int
  
int オブジェクトのストリング表現を返します。
int
  
指定された int オブジェクトのプリミティブな値を返します。
int
パブリック定数
 定数定義
  MAX_VALUE : int = 2147483647
[static] 表現可能な 32 ビット符号付き整数の最大値、2,147,483,647 です。
int
  MIN_VALUE : int = -2147483648
[static] 表現可能な 32 ビット符号付き整数の最小値、-2,147,483,648 です。
int
コンストラクタの詳細
int()コンストラクタ
public 関数 int(num:Object)

コンストラクタ; 新しい int オブジェクトを作成します。int.toString()int.valueOf() を使用するには、int コンストラクタを使用する必要があります。int オブジェクトのプロパティを使用する場合は、コンストラクタを使用しません。new int コンストラクタは、主にプレースホルダーとして使用します。int オブジェクトは、パラメータをプリミティブ値に変換する int() 関数とは異なります。

パラメータ
num:Object — 作成する int オブジェクトの数値、または数値に変換する値です。value が指定されなかった場合のデフォルト値は 0 です。

関連項目



次のコードは、新しい int オブジェクトを作成します。
  var n1:int = new int(3.4);
  var n2:int = new int(-10);
  

メソッドの詳細
toExponential()メソッド
AS3 function toExponential(fractionDigits:uint):String

数値のストリング表現を指数表現で返します。ストリングには、fractionDigits パラメータでの指定に従って小数点の前に 1 桁、小数点以下に最大 20 桁が含まれます。

パラメータ
fractionDigits:uint — 必要な小数の桁数を表す 0 ~ 20 の整数です。

戻り値
String

スロー
RangeError fractionDigits 引数が 0 ~ 20 の範囲外である場合に、例外をスローします。


The following example shows how toExponential(2) returns a string in exponential notation.

var num:Number = 315003; trace(num.toExponential(2)); // 3.15e+5

toFixed()メソッド 
AS3 function toFixed(fractionDigits:uint):String

数値のストリング表現を固定小数点表現で返します。固定小数点表現とは、fractionDigits パラメータでの指定に従って、小数点以下の特定数の桁をストリングに含めたものです。fractionDigits パラメータの有効範囲は 0 ~ 20 です。この範囲外の値を指定すると例外がスローされます。

パラメータ
fractionDigits:uint — 必要な小数の桁数を表す 0 ~ 20 の整数です。

戻り値
String

スロー
RangeError fractionDigits 引数が 0 ~ 20 の範囲外である場合に、例外をスローします。


The following example shows how toFixed(3) returns a string that rounds to three decimal places.

var num:Number = 7.31343; trace(num.toFixed(3)); // 7.313

The following example shows how toFixed(2) returns a string that adds trailing zeroes.

var num:Number = 4; trace(num.toFixed(2)); // 4.00

toPrecision()メソッド 
AS3 function toPrecision(precision:uint):String

数値のストリング表現を指数表現または固定小数点表現で返します。ストリングには、precision パラメータで指定された桁数が含まれます。

パラメータ
precision:uint — 結果のストリングに必要な桁数を表す 1 ~ 21 の整数です。

戻り値
String

スロー
RangeError precision 引数が 1 ~ 21 の範囲外である場合に、例外をスローします。


The following example shows how toPrecision(3) returns a string with only three digits. The string is in fixed-point notation because exponential notation is not required.

var num:Number = 31.570; trace(num.toPrecision(3)); // 31.6

The following example shows how toPrecision(3) returns a string with only three digits. The string is in exponential notation because the resulting number does not contain enough digits for fixed-point notation.

var num:Number = 4000; trace(num.toPrecision(3)); // 4.00e+3

toString()メソッド 
AS3 function toString(radix:uint):String

int オブジェクトのストリング表現を返します。

パラメータ
radix:uint — 数値からストリングへの変換に使用する基数 (2 ~ 36) を指定します。radix パラメータを指定しない場合、デフォルト値は 10 です。

戻り値
String — ストリング。


次の例では、radix パラメータに 2 および 8 を使用し、数値 9 に対応する表現を含むストリングを返します。
  var myint:int = new int(9);
  trace(myint.toString(2)); // output: 1001
  trace(myint.toString(8)); // output: 11
  

次の例では、結果が 16 進数値になります。

  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); // 0xfa8072
  

valueOf()メソッド 
AS3 function valueOf():int

指定された int オブジェクトのプリミティブな値を返します。

戻り値
int — int 値です。


次の例では、numSocks オブジェクトのプリミティブな値が結果として返されます。
  var numSocks:int = new int(2);
  trace(numSocks.valueOf()); // 2
  

定数の詳細
MAX_VALUE定数
public static const MAX_VALUE:int = 2147483647

表現可能な 32 ビット符号付き整数の最大値、2,147,483,647 です。



次の ActionScript は、表現可能な最大および最小の int オブジェクトを [出力] パネルにログファイルに表示し書き込みます。
 trace("int.MIN_VALUE = "+int.MIN_VALUE);
 trace("int.MAX_VALUE = "+int.MAX_VALUE);
 

このコードは、次の値を記録表示します。

 int.MIN_VALUE = -2147483648
 int.MAX_VALUE = 2147483647
 

MIN_VALUE定数 
public static const MIN_VALUE:int = -2147483648

表現可能な 32 ビット符号付き整数の最小値、-2,147,483,648 です。



次の ActionScript は、表現可能な最大および最小の int オブジェクトを [出力] パネルにログファイルに表示し書き込みます。
     trace("int.MIN_VALUE = "+int.MIN_VALUE);
     trace("int.MAX_VALUE = "+int.MAX_VALUE);
     

このコードは、次の値を記録表示します。

 int.MIN_VALUE = -2147483648
 int.MAX_VALUE = 2147483647
     


The following example uses the IntExample class to show how to work with and check the validity of int data types:
  1. Two int variables a and b are declared in the constructor.
  2. The two ints are added using the method addIntegers().
  3. A third int variable c is assigned the outcome of parseInteger(), which checks the validity of the string passed to it to ensure that 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.
  4. The int variables a and c are 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; }
        
    } }